Created
December 1, 2017 09:42
-
-
Save smkamranqadri/a9700b7cdffc8fa7c8b24c8c9e1e368c to your computer and use it in GitHub Desktop.
Two questions... 1. How you can improve this code? 2. Do you validate the param is available?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/users/:id', (req, res) => { | |
const userId = req.params.id | |
if (!userId) { | |
return res.sendStatus(400).json({ | |
error: 'Missing id' | |
}) | |
} | |
Users.get(userId, (err, user) => { | |
if (err) { | |
return res.sendStatus(500).json(err) | |
} | |
res.send(users) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment