Skip to content

Instantly share code, notes, and snippets.

@JosielFaleiros
Last active July 25, 2019 17:52
Show Gist options
  • Save JosielFaleiros/f03aa4df6de9b7655ed2512500b6e010 to your computer and use it in GitHub Desktop.
Save JosielFaleiros/f03aa4df6de9b7655ed2512500b6e010 to your computer and use it in GitHub Desktop.
const { performance } = require('perf_hooks');
const app = express();
const logRequestStart = (req, res, next) => {
var t0 = performance.now();
console.info(`\n\n\n${req.method} ${req.originalUrl}\n\n`);
res.on('finish', () => {
var t1 = performance.now();
// console.log("Call to doSomething took " + + " milliseconds.")
console.info(`\n\n\n\n [FINISH] ${req.method} ${req.originalUrl} ${res.statusCode} ${res.statusMessage}; ${res.get('Content-Length') || 0}b sent IN ${((t1 - t0) / 1000).toFixed(2)} SECONDS\n\n\n`)
})
next()
}
app.use(logRequestStart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment