showing results for - "express response time"
Alexander
11 Sep 2016
1const express = require('express');
2const bodyParser = require('body-parser');
3const responseTime = require('response-time')
4const app = express();
5
6// use JSON
7app.use(bodyParser.json());
8app.use(bodyParser.urlencoded({ extended: true }));
9
10// add ResponseTime Funtion
11app.use(responseTime((req, res, time) => {
12  // log the responseTime with URL and method
13  console.log(`${req.method} ${req.url} ${time}`);
14}))
15app.get('/', (req, res) => {
16  res.send('foo');
17});
18app.listen(3000);
19
20// Logs something like:  GET / 0.9935419999999997