Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How do I extract an object from a promise?

I'm trying get some information out of a nosql database and then read that information through my template engine (handlebars), But I have no idea how to do it

all i'm getting is this message: enter image description here

here's some of the code I wrote thinking it could work

let blogPosts = blog.find().where().exec(function(err, blogInfo){
    return blogInfo
});

router.get('/', function(req, res) {
    res.render("blog-home", {blogposts: blogPosts})
});

thanks.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You have to wait for the promise to resolve and then render the template, once the value is there.

router.get('/', function(req, res) {
    let blogPostsPromise = blog.find().where().exec(function(err, blogInfo) {
        return blogInfo
    });  

    blogPostsPromise
       .then(blogPosts => res.render("blog-home", { blogposts: blogPosts }))
       .catch(next);
});
over 4 years ago · Santiago Trujillo Relatório

0

To extract an object from a promise you have to wait for the promise to finish. You do it by using ".then" on the promise.

let blogPosts = blog.find().where().exec(function(err, blogInfo){
    return blogInfo
});

router.get('/', function(req, res) {
    blogPosts.then(function (posts) {
        res.render("blog-home", {blogposts: posts});
    });
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda