Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda