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

171
Visualizações
variable value showing undefine even update in async function

I try to get the data from a function by using variables. first I declare a variable empty and then inside the function, I store some data from the DB in a variable. try-catch sending the data properly but when I console the variable after the function then it's showing undefined.

let custDetail;



const dashboardReq = async (req, res, next) => {
    try {
        const regCust = await registeredUser.findOne({
            mobile: req.params.mobile
        });

        if (regCust == null) {
            console.log("No user found");
        }
        custDetail = await registeredUser.findOne(req.params);

        res.status(201).json({
            status: "success",
            data: {
                custDetail
            },
        });
    } catch (error) {
        res.status(400).json({
            status: "fail",
            data: next(error),

        });


    }


};

console.log(custDetail);
about 4 years ago · Juan Pablo Isaza
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