Each then() should return a value or throw – promise/always-return in node JavaScript Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Each then() should return a value or throw – promise/always-return in node JavaScript without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have tried the code from sample code but there is an error while deploying the error is

42:7  error  Each then() should return a value or throw  promise/always-return

Here is the code

db.collection('users').get().then((snapshot) => {
    if (!doc || !doc.exists) {
        throw new Error("data does not exists");
    }
    snapshot.forEach((doc) => {
        return  console.log(doc.id, '=>', doc.data());
    });
})
.catch((err) => {
    return  console.log('Error getting documents', err);
});

Answer

In your example above you are returning from the forEach function, not the then. I would change it to

return snapshot.map(doc => {
   ...
})
We are here to answer your question about Each then() should return a value or throw – promise/always-return in node JavaScript - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji