Answer the question
In order to leave comments, you need to log in
How to pass an Express handler?
There is a get handler
router.get('/', function(req, res, next) {
...Тут действия с бд
next();
}
router.get('/', function(req, res, next) {
...Тут следующие действия
next();
}
Answer the question
In order to leave comments, you need to log in
next(); should be called in the callback / then of the asynchronous function The
database has not yet returned a value (only sent), and next() has already worked
router.get('/', function(req, res, next) {
someaction({query}, (error, data) => { // тут от БД зависит, может быть через промисы
if(data) next();
})
}
router.get('/', async function(req, res, next) {
try {
await someaction(query);
next();
}
catch(error){
console.error(error);
}
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question