To add timestamp to logs using Node.js library Winston, we set the transports property to an array with the Winston console object with the timestamp option set to true.
For instance, we write
const winston = require("winston");
const logger = new winston.Logger({
transports: [new winston.transports.Console({ timestamp: true })],
});
to create the Logger with the transports property set to an array with an array of loggers.
We create a logger with the Console constructor by calling it with an object with the timestamp property set to true to add a timestamp to each log entry.