MERN Quick Start Guide
上QQ阅读APP看书,第一时间看更新

Modular route handlers

ExpressJS has a built-in class called router. A router is just a class that allows developers to write mountable and modular route handlers.

A Router is an instance of ExpressJS' core routing system. That means, all routing methods from an ExpressJS application are available:

const router = express.Router() 
router.get('/', (request, response, next) => { 
  response.send('Hello there!') 
}) 
router.post('/', (request, response, next) => { 
  response.send('I got your data!') 
})