Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```js
- const albums = require('express').Router();
- const tracks = require('./tracks').Router();
- //...
- // Our root route to /albums
- albums.get('/', function(req, res, next) {
- // res.send() our response here
- });
- // A route to handle requests to any individual album, identified by an album id
- albums.get('/:albumId', function(req, res, next) {
- let albumId = req.params.albumId;
- // retrieve album from database using albumId
- // res.send() response with album data
- });
- // Note, this route represents /albums/:albumId/tracks because our top-level router is already forwarding /albums to our Albums router!
- albums.use('/:albumId/tracks', tracks);
- //...
- module.exports = albums;
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement