npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

simple-auth-middleware

v1.0.2

Published

Middleware Framework for authentication of ExpressJS Routes

Readme

simple-auth-middleware

NPM Version NPM Downloads Node.js Version

Middleware Framework for authentication of ExpressJS Routes.

Installation

$ npm install simple-auth-middleware

API Information

The simple-auth-middleware framework was developed to authenticate the web server routes proposed by ExpressJS. Basically the module obtains the password informed in requests routes to be compared to the default username and password, or through a new authentication method that the developer can inform the Framework. The parameters "user" and "passwd" to be sent in the QueryString in the header or body of the request on the x-www-form-urlencoded format.

The constructor of the authentication module has two parameters that can be omitted:

  • userDefault: indicates the default user for authentication of the routes. If no atenticação method is set, all authentication will be based on this user.
  • passwordDefault: indicates the default password for authentication of the routes. If no atenticação method is set, all authentication will be based on this password.

If these parameters and a new authentication method are not informed authentication is not performed.

Extension

The Framework allows extension through 4 key points.

  • userDefault: Sets the default user. This user is used for authentication when no method is passed by the developer;
...
var authMiddle = require ( 'simple-auth-middleware');
authMiddle ( 'user.default' 'pswd.default');

authMiddle.userDefault = 'new.user.default';
...
  • pwdDefault: Set the default password. This password will be used for authentication when no method is passed by the developer;
...
var authMiddle = require ( 'simple-auth-middleware');
authMiddle ( 'user.default' 'pswd.default');

authMiddle.pwdDefault = 'new.pswd.default';
...
  • unauthMessageFunction: This item allows the developer to change the return Response when authentication is denied. This point allows the developer to customize the message.
...
var authMiddle = require ( 'simple-auth-middleware');
authMiddle ( 'user.default' 'pswd.default');

var unauthMessage = function (res) {
           res.status (401) .send ( '<h1> Stop Man </ h1><br><h3> You do not have the password, you can not enter <h3>.');
    };

authMiddle.unauthMessageFunction = unauthMessage;
...
  • accessGranted: This item allows the developer to change the authentication method. This point allows the user to access a database and assess whether the user has access to functionality for example. The return of the function must be a boolean, true and false guarantees access denied.
...
var authMiddle = require ( 'simple-auth-middleware');
authMiddle ( 'user.default' 'pswd.default');

var accessGranted = function (user, pwd) {
         userFromDB = findUserFromDB (user);
pwdFromDB = findPWDFromDB (pwd);
         return ((user === userFromDB) && (pwdFromDB === pwd));
    };

authMiddle.accessGranted = accessGranted;
...

API for all Routes

  • Simple use of the Framework, including authentication for all application routes.
var express      = require('express');
var bodyParser   = require('body-parser');
var authMiddle   = require('simple-auth-middleware');

var app = express()
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

app.use(authMiddle('user.default','pswd.default'))

API for Route-specific

  • Using the Framework, only the specific routes of application.
var express      = require('express');
var bodyParser   = require('body-parser');
var authMiddle   = require('simple-auth-middleware');

var app = express()
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

simpleAuth = authMiddle('user.default','pswd.default');

app.get('/test', function (req, res) {
    res.json({message: "auth test ok!!"});
});

app.post('/test', simpleAuth, function (req, res) {
    res.json({message: "auth post test ok!!"});
});

MIT Licensed