Express Router

PHOTO EMBED

Sat Jan 06 2024 14:47:46 GMT+0000 (Coordinated Universal Time)

Saved by @Hritujeet

const express = require('express')
const router = express.Router()

// middleware that is specific to this router
router.use((req, res, next) => {
  console.log('Time: ', Date.now())
  next()
})
// define the home page route
router.get('/', (req, res) => {
  res.send('Birds home page')
})
// define the about route
router.get('/about', (req, res) => {
  res.send('About birds')
})

module.exports = router

// Importing this file for routes
const birds = require('./birds')

// ...

app.use('/birds', birds)
content_copyCOPY