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

255
Views
Not returning correct value in .then() / Node.js

I was coding a simple Google Firebase Cloud Firestore system in node.js, and I put the script in another file. I wrote a function to get the data from a document, but when I tested it, it didn't work. Doing a console.log from the .then() works perfectly fine, but I need to pass the value to another script.

Function:

// firebase.js
async function getAllDocsFromCollection(collection){
  let data = [];
  db.collection(collection).get().then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      data.push(doc.id);
      data.push(doc.data());
    });
    console.log(data); // Logs correct data
  });
  console.log(data); // Doesn't log correct data
  return data; // Doesn't return correct data
}
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!