express-auth-middle is an authentication middleware for Express.js applications, offering support for both standard HTTP Basic Authentication and a custom `X-Auth` header scheme. Written in TypeScript, it provides type safety and integrates cleanly into Express applications. The current stable version is 1.1.2, with the last publish occurring approximately three years ago, suggesting a maintenance-level release cadence rather than active feature development. Key differentiators include its dual-method authentication approach (allowing either basic or x-auth, or both), the ability to define custom credentials, and an optional `challenge` flag to prompt clients for credentials via the `WWW-Authenticate` header. It is designed for straightforward integration into existing Express middleware chains.
npm install express-auth-middleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `express-auth-middle` to secure all routes using both X-Auth and Basic Authentication methods, and provides example `curl` commands.
Store `basicAuthUname`, `basicAuthPword`, and `xAuthorisationKey` securely in environment variables (e.g., using `dotenv`) and never hardcode them in your application code or commit them to version control.
Ensure you are using `import authMiddleWare from 'express-auth-middle';` in an ESM-enabled project (e.g., `"type": "module"` in `package.json`). For older CommonJS projects, you might need a transpilation step or a different middleware.
Always ensure that the credentials required by the `methods` specified in the middleware options are fully and correctly provided in the `credentials` object.
Periodically audit your dependencies and consider if a more actively maintained authentication solution is necessary for long-term security. Monitor the project's GitHub for any security advisories.
Ensure your project is configured for ESM and use `import authMiddleWare from 'express-auth-middle';`. If using CommonJS, explicit handling of default exports (e.g., `require('express-auth-middle').default`) might be needed, but migrating to ESM is recommended.Verify that the `xAuthorisationKey`, `basicAuthUname`, and `basicAuthPword` in your middleware configuration exactly match the values sent by the client. Check for typos, incorrect encoding for Basic Auth, or missing headers.
Run `npm install express-auth-middle` or `yarn add express-auth-middle`. If already installed, check your `tsconfig.json` paths or module resolution settings if using TypeScript.