Skip to content

Instantly share code, notes, and snippets.

@ibakhtin
Created January 1, 2019 20:10
Show Gist options
  • Save ibakhtin/06693358f55a82943b47a9b91412b490 to your computer and use it in GitHub Desktop.
Save ibakhtin/06693358f55a82943b47a9b91412b490 to your computer and use it in GitHub Desktop.
const asyncMiddleware = fn => (req, res, next) => {
Promise.resolve(fn(req, res, next).catch(next);
};
const getUser = async (req, res, next) => {
const { id } = req.params;
const user = await User.findById(id);
}
router.get("/user/:id", asyncMiddleware(getUser));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment