Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!