找不到模块“事件”

时间:2018-08-02 19:18:54

标签: javascript node.js mean-stack

const EventEmitter = require('event');

const emitter = new EventEmitter();

//注册一个收听者

emitter.on('messageLogged', function() {
  console.log("listen is called ");
});

//发起活动

emitter.emit('messageLogged');

1 个答案:

答案 0 :(得分:1)

尝试要求带有s的“事件”

const EventEmitter = require('events');

https://nodejs.org/api/events.html