basic-auth is a focused Node.js module designed for parsing the 'Authorization' header field specifically for Basic HTTP Authentication. It efficiently extracts the username and password from the header string, returning them as an object with `name` and `pass` properties. The current stable version is 2.0.1, indicating a mature and stable package that receives updates primarily for dependency maintenance and minor internal improvements. It operates with a low-cadence release cycle. A key differentiator is its simplicity and direct utility, offering a lightweight solution for a common HTTP parsing task without imposing additional framework or middleware dependencies. This makes it highly versatile for integration into various Node.js HTTP servers, custom middleware, or application logic, handling edge cases such as empty usernames or passwords correctly.
Verified import paths — ran on the pinned version, not inferred.
This package is a CommonJS module. Direct ESM import syntax is not supported without a transpiler or ESM wrapper.
The primary function accepts a Node.js `http.IncomingMessage` object. Passing a raw Koa context (`ctx`) directly was deprecated in v2.0.0; use `ctx.req` instead.
The `parse` method is exposed as a property of the main `auth` export, designed for parsing raw `Authorization` header strings. It's not a named export for direct destructuring.
Demonstrates a basic Node.js HTTP server using `basic-auth` to parse incoming 'Authorization' headers and implement credential validation with `tsscmp` for security.
Breaking-change detection hasn't run for this library yet.
CVE tracking and dependency tree are planned for a later release.