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

111
Views
Async calls in express.js

In my express.js app, I would like to encapsulate my async database call into reusable function "getPerson(id)". Like so...

function getPerson(id) {
  db.get(
      `SELECT * FROM People WHERE id = ${id};`,
      (error, row) => {
        if (error || !row) {
          return false
        } else {
          return row.name
        }
      }
    )
}

But how can I "await" result from this function inside express.js request route block of code? Like so...

app.get('/person/:id', (req, res) => {
  const person = getPerson(req.params.id) // wait for this, but how?
  if (person) {
    res.status(200).send(person)
  } else {
    res.sendStatus(400)
  }
})

I have tried different combination of using async/await keywords in above code samples, but not sure how that works. Then I also read in express.js docs that async/await keywords are not even supported in express version <5. Above node.js examples use express.js 4.x and sqlite3 5.x modules. Thanks for the help.

about 4 years ago · Santiago Gelvez
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!