Registry / http-networking / basic-auth-middleware

basic-auth-middleware

JSON →
library1.0.3jsnpmunverified

The package `basic-auth-middleware` provides a foundational HTTP Basic Authentication middleware for Node.js `http` servers. Released as version 1.0.0, this package is definitively abandoned, having received its last update over seven years ago (as of April 2026). It was marked with an "experimental" stability badge even at its stable release, indicating it was never intended for long-term production use. It integrates with native `http` server requests and responses, employing a callback-based API (`middleware(req, res, ctx, done)`) for authentication flow control. Error objects are constructed using the `boom` library, which is itself deprecated. Due to its unmaintained status and dated design patterns, it is not suitable for new projects and poses potential security and maintenance risks for existing applications.

npm install basic-auth-middleware
INSTALL
IMPORT
SIG · BASIC-AUTH-MIDDLEW
B
basic-auth-middleware
http-networkingjavascriptv1.0.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.

Auth
const Auth = require('basic-auth-middleware')
import Auth from 'basic-auth-middleware'
This package only provides a CommonJS export. ES Modules (ESM) syntax like `import` is not supported. There are no TypeScript type declarations provided by the package.

Demonstrates setting up a basic HTTP server with basic authentication using environment variables for credentials. It shows successful and failed authentication scenarios.

const Auth = require('basic-auth-middleware'); const http = require('http'); const USERNAME = process.env.BASIC_AUTH_USERNAME || 'my-username'; const PASSWORD = process.env.BASIC_AUTH_PASSWORD || 'some-password'; const PORT = process.env.PORT || 3000; const auth = Auth(USERNAME, PASSWORD); const server = http.createServer(function (req, res) { const ctx = {}; // Context object, can be used for passing data auth(req, res, ctx, function (err) { if (err) { // boom errors typically have .output.statusCode res.statusCode = err.output ? err.output.statusCode : 401; res.setHeader('WWW-Authenticate', 'Basic realm="Authentication Required"'); res.end('Not authenticated. Please provide valid credentials.'); console.log('Authentication failed.'); return; } res.end('Authentication successful! Welcome.'); console.log('Authentication successful.'); }); }); server.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); console.log(`Try accessing with 'curl -u ${USERNAME}:${PASSWORD} http://localhost:${PORT}'`); console.log(`Or without credentials to fail: 'curl http://localhost:${PORT}'`); });
Debug
Known issues
breakingThis package is considered abandoned, with the last update over 7 years ago (as of April 2026). It also carried an 'experimental' stability badge even at its 1.0.0 release. It is not recommended for new projects and should be replaced in existing ones due to potential security vulnerabilities and lack of maintenance.
fix
Migrate to a actively maintained basic authentication middleware for your specific framework (e.g., 'express-basic-auth' for Express) or implement a custom, modern solution.
affects: >=1.0.0
gotchaThe middleware uses a callback-based API (`middleware(req, res, ctx, done)`) which is less common in modern async/await-centric Node.js development. This can lead to more complex error handling and control flow compared to promise-based alternatives.
fix
Wrap the middleware in a Promise or utilize an alternative package that provides a promise-based or async/await compatible API for easier integration with modern Node.js patterns.
affects: >=1.0.0
gotchaThis package relies on the 'boom' library for error objects. 'boom' is also deprecated and largely unmaintained. Consumers of the `err` object will need to handle `boom`-specific properties (e.g., `err.output.statusCode`) rather than standard JavaScript `Error` properties.
fix
Inspect the `err` object in the callback for specific `boom` properties like `err.output` or `err.isBoom`. Consider migrating to a middleware that uses standard JavaScript `Error` objects or more modern error handling patterns.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module ... not supported.
Attempting to import this CommonJS-only package using ES Modules (`import`) syntax in a modern Node.js environment.
fix
Use CommonJS `require` syntax: `const Auth = require('basic-auth-middleware');`
TypeError: auth is not a function
Attempting to call the imported module directly as a middleware function instead of first instantiating it with credentials.
fix
Ensure you create an instance by calling `Auth` with username and password: `const auth = Auth('your-username', 'your-password');` before using `auth(req, res, ctx, done);`
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
boomrequiredUsed internally for generating HTTP-friendly error objects.
Agent activity
34 hits · last 30 days
node
29
OpenAI (training)
2
Resources
basic-auth-middleware — npm install basic-auth-middleware · libregistry