I\'m trying to get the hang of using Mongoose promises with the async/await functionality of Node.js. When my function printEmployees is called I want to save t
if you're going to use async/await then it works like this.
Please have a look on this function, it is a middleware before i execute a specific route in express.
const validateUserInDB = async (req, res, next) => {
try {
const user = await UserModel.findById(req.user._id);
if (!user) return res.status(401).json({ message: "Unauthorized." });
req.user = user;
return next();
} catch (error) {
return res.status(500).json({ message: "Internal server error." })
}
}