irakilsg
irakilsg
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 await operator is used to wait for a Promise. It can only be used inside an async function.

Shouldn’t be something like

const getUser = async (req, res, ) => {...

that should have been used instead?

Thank you

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade