TypeError:Object#<function>没有方法'write'</function>

时间:2013-11-05 16:36:14

标签: javascript node.js

我是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加载了文件系统模块,但我仍然收到此错误。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案