Like any kind of apps, there are difficult issues to solve when we write Node apps.
In this article, we’ll look at some solutions to common problems when writing Node apps.
Mongoose methods return promises.
So we can use them with async
and await
.
For instance, we can write:
const orderEmployees = async(companyID) => {
try {
const employees = await User.find({ company: companyID }).exec();
console.log(employees);
return employees;
} catch (err) {
return 'error occured';
}
}
We can User.find
with a query.
That returns a promise with the resolved result.
We can also catch errors with catch
.
#web-development #javascript #software-development #technology #programming