const username = req.body.username; const password = req.body.password; if (!username) { throw new Error('Missing username'); } if (!password) { throw new Error('Missing password'); } User.findOne({ username, password }).then(user => { res.json({ user }); }).catch(err => { res.json({ err }); }); const username = req.body.username; const password = req.body.password; if (!username) { res.json({ err: 'Missing username' }); } if (!password) { res.json({ err: 'Missing password' }); } User.findOne({ username, password }).then(user => { res.json({ user }); }).catch(err => { res.json({ err }); });