@plasticut/express-async-await

Express.js async/await extention

Usage no npm install needed!

<script type="module">
  import plasticutExpressAsyncAwait from 'https://cdn.skypack.dev/@plasticut/express-async-await';
</script>

README

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