Skip to content

Instantly share code, notes, and snippets.

@Abazhenov
Last active June 8, 2018 13:09
Show Gist options
  • Save Abazhenov/ab75a3e02f63b9b47c7b9e399f2572fa to your computer and use it in GitHub Desktop.
Save Abazhenov/ab75a3e02f63b9b47c7b9e399f2572fa to your computer and use it in GitHub Desktop.
const asyncMiddleware = require('./utils/asyncMiddleware');
router.get('/users/:id', asyncMiddleware(async (req, res, next) => {
/*
if there is an error thrown in getUserFromDb, asyncMiddleware
will pass it to next() and express will handle the error;
*/
const user = await getUserFromDb({ id: req.params.id })
res.json(user);
}));
router.post('/users', asyncMiddleware(async (req, res, next) => {
const user = await makeNewUser(req.body);
res.json(user)
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment