How to add dates to pm2 error logs with Node.js?

Sometimes, we want to add dates to pm2 error logs with Node.js.

In this article, we’ll look at how to add dates to pm2 error logs with Node.js.

How to add dates to pm2 error logs with Node.js?

To add dates to pm2 error logs with Node.js, we can run pm2 with the `–log-date-format option.

For instance, we run

pm2 start app.js --log-date-format 'DD-MM HH:mm:ss.SSS'

to run pm2 to start app.js and add dates to the log by specifying the --log-date-format option to add a date to each log entry in format DD-MM HH:mm:ss.SSS.

DD-MM HH:mm:ss.SSS is a moment format date string with the date, month, houts, minutes, seconds and milliseconds in this order.

Conclusion

To add dates to pm2 error logs with Node.js, we can run pm2 with the `–log-date-format option.