0

I am able to console.log the output properly, but when I try to return the array, it fails (ie: no output)


    //get all geo route
    app.get('/api/geo', function(req, res){
       res.send(getGeo());
    });

    async function getGeo() {
      let query = firestore.collection('geo'); //.where('foo', '==', 'bar');

      let response = await query.listDocuments().then(documentRefs => {
        return firestore.getAll(...documentRefs);
      }).then(documentSnapshots => {
         let geomatches = [];
         for (let documentSnapshot of documentSnapshots) {
            if (documentSnapshot.exists) {
              //console.log(`Found document with data: ${documentSnapshot.id}`);
              geomatches[documentSnapshot.id] = documentSnapshot.data();
            }//if
         }//for
         return geomatches;
      });

      return response;

    }

2 Answers 2

1

getGeo() is an async function. You should use await to call it. Also declare your route callback as async:

//get all geo route
app.get('/api/geo', async function(req, res){
   res.send(await getGeo());
});
Sign up to request clarification or add additional context in comments.

Comments

1

use await

  //get all geo route
   app.get('/api/geo', async function(req, res){
      res.send( await getGeo());
   });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.