我是 node.js 的新手,正在尝试创建我的第一个模块。但我收到一个错误
TypeError: Object function SetAstAppLog.....has no method 'on'
我的模块文件包含以下代码:
var EventEmitter = require('events').EventEmitter;
var util = require('util');
module.exports = SetAstAppLog;
util.inherits(SetAstAppLog, EventEmitter);
function SetAstAppLog(logFolderPath,fileNamePrefix,fileSize,logStreamObject) {
EventEmitter.call(this);
.
.
.
.
this.emit('objCreated');
}
在 app.js 中,我正在做以下事情:
var SetAstAppLog = require('astAppLog');
var fileSize = 1024;
SetAstAppLog.on('objCreated', function () {
console.log('an object was created');
});
SetAstAppLog.on('written', function () {
console.log('Write operation completed.');
});
var objCommLogger = new SetAstAppLog(logFolderPath,logCommFilePrefix,fileSize,logCommMsg);
var objErrorLogger = new SetAstAppLog(logFolderPath,logErrorFilePrefix,fileSize,logErrorMsg);
在这里,我使用 v0.10.21 的 node js。
即使我的模块文件包含我也无法找出为什么我会收到此错误EventEmitter
任何人都可以帮助解决此问题吗?