Tutorial by Examples

The main app file loads the routes file where routes are defined. app.js var express = require('express'); var app = express(); app.use('/', require('./routes')); app.listen('3000'); routes.js var router = require('express').Router(); router.get('/', function(req, res) { res.sen...
Middleware is executed prior to the route execution and can decide whether to execute the router according to the URL. var router = require('express').Router(); router.use(function (req, res, next) { var weekDay = new Date().getDay(); if (weekDay === 0) { res.send('Web is clos...
The main app file loads any routes files in which you would like to define routes. To do so we need the following directory structure: app.js routes/index.js routes/users.js app.js var express = require('express'); var app = express(); app.use('/', require('./routes/index')); app.use('/us...

Page 1 of 1