Answer the question
In order to leave comments, you need to log in
What are the situations in which you can't do without app.param in Express?
In what situations can you not do without app.param? After all, actions can be done immediately in app.get.
app.param('userId', (req, res, next) => {
// some actions
next()
})
app.get('/users/:userId', (req, res) => {
// some actions
res.end()
})
Answer the question
In order to leave comments, you need to log in
There are no such situations, but sometimes it is more convenient with him.
For example, when you have several different routes with this parameter.
app.param('userId', (req, res, next) => {
// тут какой-то длинный код
next();
});
app.get('/users/:userId', (req, res) => { ... });
app.get('/users/:userId/info', (req, res) => { ... });
app.post('/users/:userId', (req, res) => { ... });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question