1.0.0 • Published 2 years ago

express-async-support v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

A hack of express to support async handler. Slightly Modified from express-async-errors

Install

yarn add express-async-support

Usage

const express = require('express')
require('express-async-support')
app = express()

// directly use async hanlder
app.get('/hello', async (req, res) => {
  throw new Error('oops!')
  res.send('hello!');
});

// errors thrown from handlers are passed to the error handler
app.use((err, req, res, next) => {
  res.status(500);
  res.json({ error: err.message });
  next(err);
});