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

175
Views
Understanding await purpose within an async function in NODE

My question has to do with the await purpose in node.js. I'm going to write some dummy code in order to express my question, so please don't mind if there's something missing:

let f = async function(x) {
    var data = await readFile('x.txt');
    var link = openLink(`./myfile/${data}`);
    return link;
}

So, as I understand it, f will run in a separate thread from the Nodejs Event Loop while it expects the returning 'promised' value of link. When that new thread opens, the function gets executed synchronously within that thread - but if that's true, why bother with the await? I mean, the function content is executed from top to bottom, like in any synchronous programming language, so it already naturally "waits" for readFile to complete in order to continue to the next line and use data as a parameter.

I'm surely misunderstanding something here, but as I read articles and documentation about async await it doesn't get clearer for me why the await must be there.

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!