I'm building a node js app(for learning) where i'm logging each operation into a file called log.txt
The logger module has the following code :
var fs = require('fs');
function write(data,filename)
{
var entry = 'Time: '+new Date();
if(filename !=null || filename != undefined) entry = entry+'\n\tFile: '+filename;
if(data !=null || data != undefined) entry = entry+'\n\tMessage: '+data;
entry = entry+'\n';
fs.appendFile('./log.txt',entry,function(err){
if(err){console.log('Log NOT Appended with data:\n\t'+entry);}
else{console.log('Log Appended with data:\n\t'+entry);}
});
}
exports.write = write;
now in my app.js i'm requiring it as :
var logger = require('./logger');
var fs = require('fs');
function ReadFile()
{
var data = fs.readFileSync('./config.txt');
if(data==null)
logger.write("Config data not found");
else
logger.write(data,"app.js");
}
ReadFile();
This throws me back an error saying :
Object #<Object> has no method 'appendFile'
However this worked fine earlier on a different pc, I noticed this when tried to run my app on my system.
这是版本的问题,我使用的v0.6.12没有该方法,我升级到v0.10.0即可解决该问题,这要感谢michaelt指出。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.