If you want to measure the overall response time (including creating views and passing data to the socket), you can use req._startTime defined in the startRequestTimer middleware, or use response-time , which gives much more accurate results.
This middleware adds an X-Response-Time header to all HTTP responses, so you can check it both on the client side and on the server side.
module.exports.http = { middleware: { order: [ 'responseTimeLogger', // ... ], // Using built-in variable defined by Sails responseTimeLogger: function (req, res, next) { req.on("end", function() { sails.log.info('response time: ' + new Date() - req._startTime + 'ms'); }); next(); }, // Using response-time middleware responseTimeLogger: function (req, res, next) { req.on("end", function() { sails.log.info('response time: ' + res.getHeader('X-Response-Time')); }); require('response-time')()(req, res, next); } } }
abeja
source share