Skip to content

guisehn/express-async-await-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express Async Await Errors

Make Express.js handle async errors graciously.

Installation

npm install express-async-await-errors --save

Usage

'use strict'

const express = require('express')
const app = express()

const { catchAsyncErrorsOnRouter } = require('express-async-await-errors')
catchAsyncErrorsOnRouter(app) // you can also pass an express.Router() instead of the app

app.get('/', async (req, res) => {
  throw new Error("I'm an asynchronous error being caught!")
})

app.use(function(err, req, res, next) {
  res.status(500).send(`
    <h1>Server Error</h1>
    <pre>${err.stack}</pre>
  `)
})

app.listen(3000, () => console.log(`Example app listening on port 3000!`))

About

Make Express.js handle async errors graciously

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •