1var express = require('express');
2var router = express.Router();
3
4// middleware that is specific to this router
5router.use(function timeLog (req, res, next) {
6 console.log('Time: ', Date.now());
7 next();
8});
9// define the home page route
10router.get('/', function (req, res) {
11 res.send('Birds home page');
12});
13// define the about route
14router.get('/about', function (req, res) {
15 res.send('About birds');
16});
17
18module.exports = router;
1app.get('/users/:userId/books/:bookId', function (req, res) {
2 res.send(req.params)
3})
4
1var express = require('express')
2var router = express.Router()
3
4// middleware that is specific to this router
5router.use(function timeLog (req, res, next) {
6 console.log('Time: ', Date.now())
7 next()
8})
9// define the home page route
10router.get('/', function (req, res) {
11 res.send('Birds home page')
12})
13// define the about route
14router.get('/about', function (req, res) {
15 res.send('About birds')
16})
17
18module.exports = router
19
1Route path: /flights/:from-:to
2Request URL: http://localhost:3000/flights/LAX-SFO
3req.params: { "from": "LAX", "to": "SFO" }
4
1var express = require('express');
2
3var router = express.Router();
4
5router.get('/', function(req, res) {
6 res.send('GET handler for /dogs route.');
7});
8
9router.post('/', function(req, res) {
10 res.send('POST handler for /dogs route.');
11});
12
13module.exports = router;