Registry / web-framework / use-express-middlewares

use-express-middlewares

JSON →
library0.1.0jsnpmunverified

The `use-express-middlewares` package provides a utility to adapt traditional Express.js middleware functions, which typically follow the `(req, res, next)` callback pattern, for use within environments that expect middleware to return a Promise. Its core function is to ensure that any wrapped Express middleware yields a Promise, signifying its completion. Released at version 0.1.0, and with its last apparent activity in 2016 (based on the copyright notice), this package is considered abandoned. While it aimed to bridge a gap for asynchronous middleware workflows, the evolution of Node.js and Express.js, particularly with native async/await support and Express 5's improved async middleware handling, has largely superseded the need for such a specific wrapper.

npm install use-express-middlewares
INSTALL
IMPORT
SIG · USE-EXPRESS-MIDDLE
U
use-express-middlewares
web-frameworkjavascriptv0.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wrap
✓ const wrap = require('use-express-middlewares');
✗ import wrap from 'use-express-middlewares';
This package is a CommonJS module from 2016. Use `require()` for Node.js environments. Direct ESM `import` will likely fail without transpilation or custom module resolution.
wrapExpressMiddleware
✓ const { wrapExpressMiddleware } = require('use-express-middlewares');
✗ import { wrapExpressMiddleware } from 'use-express-middlewares';
Assuming a named export, though the primary pattern is often a default export for simple utility packages of this era. Confirm actual export structure if facing issues.

Demonstrates wrapping a traditional Express middleware into a Promise-returning function, then simulating its usage in an asynchronous context that expects a promise.

const express = require('express'); const wrapMiddleware = require('use-express-middlewares'); const app = express(); const port = 3000; // A typical Express middleware (callback-based) const loggerMiddleware = (req, res, next) => { console.log(`[Express Log] ${req.method} ${req.url} at ${new Date().toISOString()}`); next(); // Call next to pass control to the next middleware }; // Wrap the Express middleware to return a Promise const promiseLoggerMiddleware = wrapMiddleware(loggerMiddleware); // Simulate a 'use-*' context that expects a Promise async function processRequest(req, res) { try { console.log('--- Starting Request Processing ---'); await promiseLoggerMiddleware(req, res); console.log('--- Wrapped Middleware Completed ---'); // Continue with other promise-based operations or send response res.status(200).send('Request processed successfully via wrapped middleware.'); } catch (error) { console.error('Error in processing:', error); res.status(500).send('An error occurred.'); } } // Example of using the wrapped middleware directly in a route handler app.get('/', async (req, res) => { // In a real 'use-*' framework, this would be handled by the framework itself. // Here, we manually call and await it to demonstrate its promise-returning nature. await processRequest(req, res); }); app.listen(port, () => { console.log(`Server listening at http://localhost:${port}`); console.log('Access http://localhost:3000/ in your browser.'); });
Debug
Known issues
breakingThis package is effectively abandoned, with no updates since 2016. It may contain unaddressed security vulnerabilities, lack compatibility with modern Node.js versions (e.g., Node.js 16+), and is unlikely to receive bug fixes or new features. Consider using native `async` middleware in Express 5 or well-maintained alternatives.
fix
Migrate to native async Express middleware or a currently maintained promise-based middleware solution. For Express 5+, middleware can be `async` functions that implicitly return a promise.
affects: >=0.1.0
gotchaThe package is a CommonJS module. Attempting to `import` it directly in an ES Module (ESM) environment will result in a `SyntaxError` or `ERR_REQUIRE_ESM` unless a CJS-to-ESM wrapper or bundler configuration is used.
fix
Use `const wrapMiddleware = require('use-express-middlewares');` in CommonJS files. For ESM projects, consider using a transpiler (e.g., Babel) or a bundler (e.g., Webpack, Rollup, esbuild) that can handle CJS modules, or rewrite the functionality using modern async patterns.
affects: >=0.1.0
gotchaDesigned for older versions of Express.js (likely 4.x or earlier). Its behavior and compatibility with Express 5.x, which has improved native support for async middleware, are uncertain and could lead to unexpected issues or redundant wrapping.
fix
Thoroughly test with your specific Express.js version. For new projects or upgrades, prioritize native Express 5 async middleware features over this wrapper.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: wrapMiddleware is not a function
Attempting to use `import wrapMiddleware from 'use-express-middlewares';` in a project configured for ES Modules, while the package itself is CommonJS and not exported as a default ES module.
fix
Change the import statement to `const wrapMiddleware = require('use-express-middlewares');`.
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/project/node_modules/some-esm-dependency.js from /path/to/project/node_modules/use-express-middlewares/index.js not supported.
While `use-express-middlewares` is CJS, it might indirectly try to `require` a dependency that has since become ESM-only, leading to an incompatibility in older Node.js versions or specific project configurations.
fix
Upgrade Node.js to a version that handles CJS/ESM interop better, or identify and update the problematic dependency if possible. Given the abandonment of `use-express-middlewares`, replacing it is the most robust solution.
Request hangs indefinitely / Middleware does not complete
The original Express middleware wrapped by `use-express-middlewares` did not correctly call `next()` or implicitly threw an error that was not caught or explicitly rejected by the wrapper's promise, causing the promise to never resolve/reject.
fix
Ensure that the original Express middleware explicitly calls `next()` (or `res.send()`, `res.end()`, etc.) or throws an error. Debug the execution path of the wrapped middleware to ensure its internal promise resolves or rejects under all conditions.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
use-express-middlewares — npm install use-express-middlewares · libregistry