0

I have my ReactJS and NodeJS/ExpressJS project up and running inside an instance. If there were to be a problem/error while the NodeJS is running, is there a way to report/write to a file in a particular directory to keep track of all the server issues?

For example, if it were to crash, it would write the error/issue to a file, so error logging to a file.

Thank you in advance and will accept/upvote answer.

2 Answers 2

3

You can use morgan to do the magic.

const fs = require('fs')
const logger = require('morgan');

app.use(logger('common', {
    stream: fs.createWriteStream('./access.log', {flags: 'a'})
}));

app.use(logger('dev'));

It will do both write into a file and show in console.

Ref to the answer

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

Comments

0

You can use Winston package with transport to and add it to middleware.

  winston.configure({
    transports: [
      new (winston.transports.File)({ filename: 'somefile.log' })
    ]
  });

Or just use express-winston

Comments

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.