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

102
Views
I have a problem with asynchronism in Nodejs

I have a problem in Nodejs, the sessionData variable gets its value from a database, in the case that this value exists new client must be executed, the problem I have is that when I run all the code first to run is new client and then get the data from sessionData, how can I do to first get the value of sessionData and then run new client

let sessionData

(async() => { 
sessionData = await cargarSession()
console.log('Mi objeto recibido', sessionData)

//return sessionData 

})();

const wa = new Client({
restartOnAuthFail: true,
puppeteer: {
    headless: true,
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--no-zygote',
        '--single-process', 
        '--disable-gpu',
        '--use-gl=egl'
    ],
}, 
session: sessionData

})

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

All you would need to do is move the client creation into the async function.

You also mentioned in the comments that you attempted that however the rest of the script was not able to access the wa object later in the script. To fix that just define wa outside of the async function and reassign it's value.

let wa;

(async() => { 
let sessionData = await cargarSession()
console.log('Mi objeto recibido', sessionData)

wa = new Client({
restartOnAuthFail: true,
puppeteer: {
    headless: true,
    args: [
        '--no-sandbox',
        '--disable-setuid-sandbox',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--no-zygote',
        '--single-process', 
        '--disable-gpu',
        '--use-gl=egl'
    ],
}, 
session: sessionData
})
})();


about 4 years ago · Juan Pablo Isaza Report
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!