var express = require('express');
var app = express();
//Simple request time logger
app.use(function(req, res, next){
console.log("A new request received at " + Date.now());
//This function call is very important. It tells that more processing is
//required for the current request and is in the next middleware function/route handler.
next(); });
app.listen(3000);
var express = require('express')
var app = express()
var myLogger = function (req, res, next) {
console.log('LOGGED')
next() }
app.use(myLogger)
app.get('/', function (req, res) {
res.send('Hello World!') })
app.listen(3000)
next
var express = require('express');
var app = express();
//Middleware function to log request protocol
app.use('/things', function(req, res, next){
console.log("A request for things received at " + Date.now());
next(); });
//Route handler that sends the response
app.get('/things', function(req, res){
res.send('Things'); });
app.listen(3000);
Now whenever you request any subroute of '/things', only then it'll log the time.