Create custom logger module in nodejs

create file name: logger.js

module.exports = function (request, response, next) {
  var startTime = +new Date();
  var stream = process.stdout;
  var duration = null;

  response.on('finish', function () {
    duration = +new Date() - startTime;
    stream.write("This request took " + duration + " ms" + request + " "+ response);
  });
  
  next();
};

// used to log  the request and response and duration 

No comments:

Post a Comment