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

connect-login

v1.0.3

Published

Connect login middleware for NodeJS

Readme

node-connect-login

A simple login middleware that does not impose any methodology on you!

This module is based of of Python's Flask-Login module.

It will:

  • Store the active user’s ID in the session, and let you log them in and out easily.
  • Let you restrict views to logged-in (or logged-out) users.

However, it does not:

  • Impose a particular database or other storage method on you. You are entirely in charge of how the user is loaded.
  • Restrict you to using usernames and passwords, OpenIDs, or any other method of authenticating.
  • Handle permissions beyond “logged in or not.”
  • Handle user registration or account recovery.

Install

npm install --save connect-login

Usage

You can allso see a full example here.

var connectLogin = require('connect-login');
var loginManager = connectLogin();

loginManager.anonymousUser(function(){
	return {username: null};
});


loginManager.userLoader(function(user_id, next){
	myDB.lookup(user_id, function(err, user){
		next(err, user);
	});
});

loginManager.userSerializer(function(user){
   return user.username;
});


app.use(loginManager);

Connect Login middleware for NodeJS

API

User objects

When configuring connect-login the user argument must only have one property user.username if user.username is null or undefined, the user is assumed to be anonymous.

`connectLogin(options)

var connectLogin = require('connect-login');
var loginManager = connectLogin(options);

options.loginPath

Url to redirect users to when a login is required. defaults to /login

loginManager

The login manager is middleware that must be used by the app.

loginManager.userLoader(loadFunction)

The loadFunction function must accept the arguments loadFunction(user_id, callback) and where callack must be called with callback(err, user)

loginManager.userSerializer(storeFunction)

The storeFunction function must user object from the userLoader and return a user_id that can be used to store in a session cookie user_id = storeFunction(user)

loginManager.anonymousUser(anonymousFunction)

anonymousUser allows an anonymous user to be created and used when a user is not logged in.

anonUser = anonymousFunction()

connectLogin.loginRequired

This middleare can be used in a route to require that the user be logged in to view it. If the user is not logged in a redirect to options.loginPath is sent

app.get('/private', connectLogin.loginRequired, function(req, res){
	res.send("Shhh!");
});

Added functions to the req object

Once the loginManager is used. all req objects will have the following methods

req.login(user, rememberMe)

This can be used from within a /login route so you can set a user as being logged in.

var user = myUserLoader(some_username);
req.login(user);

req.logout()

Log out the current user

req.user

The currently logged in user

req.loginManager

The current login manager