express-promise-router is a lightweight wrapper for Express 4's native `Router` that significantly simplifies the handling of asynchronous operations by allowing middleware and route handlers to return Promises. When a Promise is returned, its resolution or rejection is automatically managed, eliminating the need for explicit `next()` calls on successful resolution or `.catch(next)` for rejections. This package is currently on version 4.1.1 and receives regular updates, typically in the form of patch and minor releases, with major versions occurring when significant changes like Node.js version support are introduced. Its primary differentiator is its seamless integration with existing Express applications as a drop-in replacement for `express.Router()`, promoting cleaner, more readable code, especially when leveraging `async/await` syntax. Unlike solutions that patch the `app` object, this library focuses specifically on router instances, allowing for granular control over promise-aware routing.
npm install express-promise-routerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize and use `express-promise-router` with an Express application, including basic `async/await` route handlers, explicit promise resolution for `next()` calls, and a global error handling middleware that captures promise rejections.
Upgrade Node.js to a supported version (>=10 for v4.x) or pin `express-promise-router` dependency to `<4.0.0`.
Ensure your Node.js version is >=4 and update any Bluebird-specific Promise logic to use native Promises or pin `express-promise-router` dependency to `<2.0.0`.
Explicitly call a response method like `res.send()`, `res.json()`, or `res.end()` within your promise chain or `async` function to send data back to the client.
Always mount an `express-promise-router` instance onto your `app` (e.g., `app.use(promiseRouter);`) and define your promise-based routes and middleware on that router instance.
Always specify a path as the first argument to router methods, for example: `router.get('/', (req, res) => { ... });`.Ensure you explicitly call `res.send()`, `res.json()`, `res.end()`, or similar Express response methods within your promise chain or `async` function body to send data back to the client.