0

I am using a simple logger to log all my request. But It does not append to file rather it creates a new instance of that file. How can I write to file without erasing the previous data. Here is my code.

var fs = require('fs');
var Console = require('console').Console;
var output = fs.createWriteStream('./stdout.log');
var errorOutput = fs.createWriteStream('./stderr.log');
var moment = require('moment');

var logger = new Console(output, errorOutput);
logger.log('Saras');
logger.error(moment().format("DD-MM-YYYY hh:mm:ss a") + ' Arya', new Error("Can't do this"));

1 Answer 1

1

Add an append flag when you call fs.createWriteStream

var errorOutput = fs.createWriteStream('./stderr.log', {'flags': 'a'});

You can check the documentation from here.

Sign up to request clarification or add additional context in comments.

1 Comment

Well, that does it... Thanks mate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.