varexpress=require('express');varapp=express();// GET method routeapp.get('/',function(req,res){res.send('GET request to the homepage');});// POST method routeapp.post('/',function(req,res){res.send('POST request to the homepage');});app.all('/secret',function(req,res,next){console.log('Accessing the secret section ...');next();// pass control to the next handler});
varcb0=function(req,res,next){console.log('CB0');next();}varcb1=function(req,res,next){console.log('CB1');next();}app.get('/example/d',[cb0,cb1],function(req,res,next){console.log('the response will be sent by the next function ...');next();},function(req,res){res.send('Hello from D!');});
varexpress=require('express');varrouter=express.Router();// middleware that is specific to this routerrouter.use(functiontimeLog(req,res,next){console.log('Time: ',Date.now());next();});// define the home page routerouter.get('/',function(req,res){res.send('Birds home page');});// define the about routerouter.get('/about',function(req,res){res.send('About birds');});module.exports=router;