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

126
Views
how to store Node js db response into a variable

I have a pcs.db with post codes and their geolocation coordinates. I am trying to extract locations from given code name.

I am able to console log the result, but am unable to store the result into a variable.

I tried .then(function) as I believe db each returns a promise. 4 hours later I am in the same spot I started in. Please help.

const sqlite3 = require('sqlite3').verbose()

    const getCoords = function (postcode) {
      let db = new sqlite3.Database('./pcs.db');
      let sql = `SELECT long, lat FROM postcodes WHERE code='${postcode}'`;

      db.each(sql, [], (err, row) => {
        if (err) {
          throw err;
        }
         console.log(row);
      });
      
      // close the database connection
      db.close();
      }

      getCoords('SM4 4')
        

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!