Answer the question
In order to leave comments, you need to log in
How to get the result of a promise when querying the database?
Good evening everyone. I’ll say that I read an article about promises on Habré, but I didn’t understand how, using my example, I can get the result of a promise, namely users from the database. The Habr article says that inside the then function, you can do the following 3 things
1. Return (return) another promise
2. Return (return) a synchronous value (or undefined)
3. Throw (throw) a synchronous error
And here is my code example:
router.get('/index', (req, res) => {
let getProfile = User.findAll({ <---- findAll - Метод sequelize а диалект у меня postgress
offset: 0, limit: 1
}).then(result => {
return result
})
.catch(console.log.bind(console));
console.log(getProfile); <------- получаю Promise результат которого мне нужен (данные из БД)
res.render('index', {data: getProfile}); <------ пробую вывести на клиенте данные из БД с помощью .ejs
});
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question