Question

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.

Was it helpful?

Solution

This was a problem with the version, i was using v0.6.12 which did not have that method, i upgraded to v0.10.0 which solved it, thanks to michaelt for pointing it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top