
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
async-express-router
Advanced tools
An express middleware for wrapping router methods (app.METHOD and express.Router()) with a customizable try / catch
An express middleware for wrapping router methods (app.METHOD and express.Router()) with a try / catch block. It wrapps every app.METHOD (expect app.use) and express.Router().METHOD that are specified in the express 4.x documentation.
npm install --save async-express-router
or with yarn:
yarn add async-express-router
const app = require('express')()
const asyncRouter = require('async-express-router')
// Pass in an express app instance
// This has to come before importing any routes
asyncRouter(app)
// Importing routes after asyncRouter(app)
const routes = require('./path/to/routes.js')
app.use(routes)
// All set. Optionally a custom error handler can be set
app.use((err, req, res) => {
// Do something with it
res.status(500).send(error.message)
})
app.listen(3000)
Now everything is prepared and all API methods will be wrapped in a try / catch block. This is most useful when working with async / await functions.
const router = require('express').Router()
router.get('/path', async (req, res) => {
const results = await someAsyncFunctionThatThrowsAnError()
// This won't execute
res.send(results)
})
module.exports = router
app.get('/path', async (req, res) => {
const results = await someAsyncFunctionThatThrowsAnError()
// This won't execute
res.send(results)
})
Even if middlewares are passed in in an array they will be wrapped with the try / catch block if they're holding an async function.
Example
// The bad middleware will fail but it is wrapped with try catch
app.get('/path', [good, good, good, bad, good], (req, res) => {
res.sendStatus(200)
})
FAQs
An express middleware for wrapping router methods (app.METHOD and express.Router()) with a customizable try / catch
The npm package async-express-router receives a total of 14 weekly downloads. As such, async-express-router popularity was classified as not popular.
We found that async-express-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.