Z
Z
Zvenem2019-10-07 18:56:02
JavaScript
Zvenem, 2019-10-07 18:56:02

How is express.Router() different from express().get in express?

​ ​ ​ ​​ ​ ​ ​​​ ​ ​ ​​ ​ ​ ​​​ ​ ​ ​

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2019-10-07
@Zvenem

Through Router, you can set routes to a separate namespace so as not to repeat

// 1 вариант
app.get('/api/users', ...)
app.post('/api/users', ...)
app.put('/api/users', ...)

let router = new Router();
// 2 вариант
router.get('/users', ...)
router.post('/users', ...)
router.put('/users', ...)

app.use('/api', router);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question