Jul 25, 2017 · 1 min read
Gerard Rovira, All, maybe I am making a mistake here but in controlers/users.js you wrote:
function getUser(req, res, next) {
const username = req.params.username;
if (username === '') {
return res.status(500).json({ error: 'Username can\'t be blank' });
}
try {
const user = await User.find({ username }).exec();
return res.status(200).json(user);
} catch (error) {
return res.status(500).json(error);
}
}According to MDN:
The
awaitoperator is used to wait for aPromise. It can only be used inside anasync function.
Shouldn’t be something like
const getUser = async (req, res, ) => {...
that should have been used instead?
Thank you