Skip to content

Instantly share code, notes, and snippets.

@smkamranqadri
Created December 1, 2017 09:42
Show Gist options
  • Save smkamranqadri/a9700b7cdffc8fa7c8b24c8c9e1e368c to your computer and use it in GitHub Desktop.
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?
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