Categories
JavaScript Answers

How to add timestamps to all console messages with Node.js?

Spread the love

To add timestamps to all console messages with Node.js, we use the log-timestamp package.

To install it, we run

npm install log-timestamp

Then we use it by writing

require("log-timestamp");
console.log("After log-timestamp");

to require the log-timestamp package.

And then we call console.log to prepend the timestamp to the log message.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *