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

330
Views
async/await no funciona en NodeJS, no espera

Estoy llamando a 2 puntos finales de API REST usando Axios en NodeJS. Estoy tratando de hacer que el código se ejecute línea por línea, pero la segunda función ( viewProfile() ) no espera para generateId();

 const generateId = async (data) => { const options = optionsBuilder("post","profile", data); try { const response = await axios(options); id = response.data.id; console.log(id); } catch (error) { console.error(error); } } const viewProfile = async (profileId) => { console.log('Test 2', profileId); const path = `blog/${profileId}`; const options = optionsBuilder("get", path); try { const response = await axios(options); console.log(response.data); } catch (error) { console.log(error); } } } ... generateId(data); viewProfile(profileId);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe ejecutarlos en un ámbito asíncrono:

 (async function(){ await generateId(data); await viewProfile(profileId); })()

De lo contrario, no se analizan para esperar y viewProfile se ejecutará justo después de generateId . :)

Como, si está utilizando el nuevo ES2022, puede await al nivel superior.

Para versiones más nuevas de Node.js:

 await generateId(data); await viewProfile(profileId);
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!