Registry / web-framework / middleware

middleware

JSON →
library1.2.3jsnpmunverified

This `middleware` package, authored by Tim Smart, provides a fundamental utility for composing functions within a request-response cycle. It was specifically designed for integration with older Node.js web frameworks like Connect and Biggie-Router, which were prevalent around its initial publication date. The package, last updated to version 1.0.0 approximately 13 years ago (around 2013), represents an early and minimalist implementation of the middleware pattern that later became a cornerstone of more widely adopted frameworks such as Express.js. It features zero direct dependencies, offering a lean and unopinionated approach to chaining processing steps in a server's request-handling pipeline. Due to its significant age, lack of a `README.md` file on npm, and the complete absence of any recent updates or active development, this package is considered abandoned. It is not recommended for new Node.js projects, which should instead utilize modern, actively maintained middleware solutions. Its utility is now largely confined to understanding historical Node.js patterns or for maintaining highly specific legacy applications built within its original ecosystem.

npm install middleware
INSTALL
IMPORT
SIG · MIDDLEWARE
M
middleware
web-frameworkjavascriptv1.2.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

middleware
const middleware = require('middleware');
import middleware from 'middleware';
This package, published in 2013, is exclusively CommonJS. ESM `import` statements will fail unless transpiled or run with specific Node.js compatibility layers.
middleware
const myMiddleware = require('middleware');
import { middleware } from 'middleware';
The package likely exports a single function as its module. Attempting to use named imports (`{ middleware }`) from an old CommonJS module in an ESM context is incorrect.
middleware
const myMiddlewareFunction = require('middleware');
When integrating with legacy frameworks like Connect, the imported 'middleware' function would be passed directly to `app.use()` or similar methods.

This quickstart demonstrates how to conceptually use the `middleware` package within a simple Node.js HTTP server. It shows the CommonJS `require` syntax and a basic `(req, res, next)` signature, simulating how such a middleware might be integrated, typically with a framework like Connect.

const http = require('http'); const middleware = require('middleware'); // Assuming 'middleware' exports a function (req, res, next) // A simulated final handler function for the HTTP server const finalHandler = (req, res) => { if (!res.headersSent) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(`Request URL: ${req.url}, Processed by middleware.\n`); } }; // Create a basic HTTP server const server = http.createServer((req, res) => { // In a real Connect/Express app, the framework handles the 'next' orchestration. // Here, we manually simulate a simple middleware chain. middleware(req, res, (err) => { if (err) { console.error('Middleware encountered an error:', err); if (!res.headersSent) { res.writeHead(500, { 'Content-Type': 'text/plain' }); res.end('Internal Server Error\n'); } return; } // If middleware calls next, proceed to the final handler finalHandler(req, res); }); }); server.listen(3000, () => { console.log('Server running on http://localhost:3000'); console.log('Access http://localhost:3000 in your browser.'); });
Debug
Known issues
breakingThis package is effectively abandoned. It was last published 13 years ago (around 2013) to version 1.0.0. There is no active maintenance, bug fixes, or security patches, making it unsuitable for new projects.
fix
Avoid using this package for new development. Migrate legacy applications to modern, actively maintained middleware solutions (e.g., Express.js, Koa, or custom middleware functions) that are compatible with current Node.js versions and best practices.
affects: >=1.0.0
gotchaThe package was developed before native ES Modules (ESM) were standard in Node.js. It uses CommonJS (`require`) exclusively. Attempting to `import` this package in an ESM context will result in module resolution errors.
fix
Ensure your project is configured for CommonJS, or use dynamic `import()` if absolutely necessary within an ESM context, though this is not recommended for an abandoned package. Prefer modern alternatives with native ESM support.
affects: >=1.0.0
deprecatedThis package was designed for a legacy Node.js ecosystem, primarily in conjunction with frameworks like Connect and Biggie-Router. Its API and internal workings may not be compatible with modern Node.js versions (e.g., v14, v16, v18+) or contemporary web frameworks.
fix
Modern Node.js development should utilize actively maintained middleware patterns and frameworks. If maintaining a legacy application, thoroughly test compatibility with specific Node.js versions.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use `import middleware from 'middleware';` in a CommonJS-only Node.js environment or a modern ESM environment without proper interoperability setup.
fix
For this legacy package, you must use `const middleware = require('middleware');`. If your project is ESM, consider migrating to modern alternatives or carefully setting up CommonJS compatibility.
TypeError: require is not a function
This error occurs if you try to use `require()` within an ES Module (ESM) file without explicitly setting up CommonJS compatibility, which is the default in ESM.
fix
If your file is an ES Module (e.g., `"type": "module"` in `package.json` or `.mjs` extension), `require` is not available by default. Use `const { createRequire } = require('module'); const require = createRequire(import.meta.url); const middleware = require('middleware');` as a workaround, but it's strongly advised to migrate to modern, ESM-compatible solutions instead of using this abandoned package.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
middleware — npm install middleware · libregistry