🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

express-async-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-async-wrapper

Wrap async express routes so exceptions can be caught by middleware.

latest
npmnpm
Version
0.1.0
Version published
Weekly downloads
359
23.37%
Maintainers
1
Weekly downloads
 
Created
Source

express-async-wrapper

Wrap async express routes so exceptions can be caught by middleware.

If you're using the awesome ES7/ES2017 async/await features in your express routes, you'll notice that when a route throws an exception it times out. This wrapper allows express to properly catch exceptions and pass them to the appropriate error handler instead.

This code was borrowed from the StrongLoop blog post on handling async/await routes in express, I take no credit for coming up with this solution, I just wanted an npm module to use in my apps.

Install

# With npm
npm install  --save express-async-wrapper

# With yarn
yarn add express-async-wrapper

Usage

If you have a async express route file, like so:

const wrap = require('express-async-wrapper')

module.exports = wrap(async (req, res) => {
  const msg = await someSlowNetworkThingy()
  res.send('Hello', msg)
})

Now your route properly returns a promise object for express that will catch any throw exceptions.

Changelog

v0.1.0

  • Initial release! 🎉 🍾

Credits

Licensed under an MIT license by Dana Woodman.

Original source code by StrongLoop (see here)

Pull requests welcome!

Keywords

express

FAQs

Package last updated on 08 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts