@plasticut/express-async-await

1.0.2 • Public • Published

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);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @plasticut/express-async-await

Weekly Downloads

5

Version

1.0.2

License

MIT

Unpacked Size

6.91 kB

Total Files

6

Last publish

Collaborators

  • plasticut