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 🙏

© 2024 – Pkg Stats / Ryan Hefner

stateless-session

v1.2.0

Published

Secure client stored session management.

Downloads

2

Readme

stateless-session

Secure client stored session management middleware. The module provides session management functionality for stateless server applications. This is achieved by encrypting the session data and storing/reading chunks of it ( depending on data size ) in an appropriate number of cookies.

Installation

	npm install stateless-session -save

Usage

It is realy simple to use just type :

	var session = require('stateless-session');
	
	app.use(session.middleware());

and you are good to go. This will setup the session for the current request.

You can access the session object and assign data to it later in your application by using the req.session object.

	var session = require('stateless-session');
	
	app.use(session.middleware());
	
	app.get('/login',function(req,res){
		req.session.start();
		req.session.username = "skpapam";
		req.session.email = "[email protected]";
		res.send("You are now logged in and your session id is "+req.session.getId());
	});
	
	app.get('/hidden',function(req,res){
		if(req.session.hasStarted()){
			res.send("This is your private page "+req.session.username)
		}
		else{
			res.send("This page is private. You have to login first")
		}
	});
	
	app.get('/logout',function(req,res){
		req.session.stop();
		res.send("You are now logged out. Your last activity was at : "+req.session.lastActivity());
	});

As you can see in the above example session tracking does not start by default in order to provide authorization functionality to applications.

When the user visits the /login we call req.session.start() that starts the session and assigns a session id then our session data will be encrypted and passed through a single cookie in our case ( small data size ) to our client. If we don t do that there will be no cookies returned to client thus all session variables will be lost.

When the user visits our /hidden page we check if the session has started and return the appropriate message.

When the user visits the /logout page we stop the session tracking which will cause our cookies to expire thus our data to delete.

You can ignore this feature and provide guest-like sessions by setting the autostart option to true ( default is false )

	var session = require('stateless-session');
	
	app.use(session.middleware({
		'autostart' : true
	}));
	
	app.get('/addName',function(req, res) {
		req.session.name = "Skevos";
		res.send("Name added");
	});
	
	app.get('/getName',function(req, res) {
		res.send("The name is : "+req.session.name);
	});

The options that you can pass to the middleware are the following :

  • key {String} Overrides the default key for encryption. See more i-encrypt
  • debug {Boolean} Debug mode switcher for encryption. See more i-encrypt
  • autostart {Boolean} Switch from authorized sessions ( false ) to guest ones ( true ) default value is false
  • prefix {String} A cookie name prefix. Default value is 's_d_'
  • c_options {Object} Cookie related options for more see cookie. By default path option is set to '/'

Limitations

Even though this module manages to overcome the 4KB cookie size limitation by distributing the data to multiple cookies based on its size there is still the overall size limitation per domain which depends on each browser. Most modern browsers will support up to 80KB of data.

Before setting your application's session to handle a big load of data please read this.

License

MIT

Copyright (c) 2016 Skevos Papamichail <[email protected]> (www.skevosp.me)