0

我是 nodejs 的新手,正在尝试创建我的第一个模块。但我收到以下错误:

TypeError: Object #<SetAstAppLog> has no method 'write'

模块代码如下:

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);
    var fs = require('fs');
    var filePath = '';
.
.
.
.
//In following code i am trying to write data in file
currLogStreamObject = fs.createWriteStream(filePath, {flags: 'a'});
currLogStreamObject.write(message + '\n');
}

我的 app.js 代码是:

var SetAstAppLog = require('astAppLog');
var fileSize = 1024;


var objCommLogger = new SetAstAppLog(logFolderPath,logCommFilePrefix,fileSize,logCommMsg);
var objErrorLogger = new SetAstAppLog(logFolderPath,logErrorFilePrefix,fileSize,logErrorMsg);

objCommLogger.on('objCreated', function () {
    console.log('an object was created');
});

objCommLogger.on('written', function () {
    console.log('Write operation completed.');
});

我已经使用加载文件系统模块,fs但我仍然收到此错误。

谁能帮我解决这个问题?

4

0 回答 0