1.0.2 • Published 6 years ago

@plasticut/express-async-await v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

express-async-await

This module adds the ability to handle exceptions that raises in async route handlers.

const {NotFound} = require('http-errors');
require('@plasticut/express-async-await');
const app = require('express')();

app.get('/user/:userId', async (req, res) => {
  const user = await User.findById(req.params.userId);

  if (!user) throw new NotFound('User not found.');

  res.status(200).json(user);
});