Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-session-lw

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-session-lw

Lightweight in memory Session management for ExpressJS with garbage collector

  • 1.0.9
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

express-session-lw

Lightweight Session management middleware for ExpressJS with garbage collection of timeout session keys.

Follow this project on github for the newest releases and updates.

Why another session middleware?

Beause express-session middleware has purposely made it's Memorystore to leak. express-Session-lw doesn't leak and has automatic hoovering of idle session keys.

Dont take my word for it:

(quote from express-session doc) Warning The default server-side session storage, Memory Store , is purposely not designed for a production environment. It will leak memory under most conditions, does not scale past a single process, and is meant for debugging and developing.

Features

  • Keys are stored in memory.

  • Garbage collection runs at specified user configurable intervals.

  • Can co-exist with CookieParser middle-ware.

  • Per session settable idle time.

  • Timeout session keys are automatically replaced by new ones , and an empty session store is associated with the new key.

Install

  npm install --save express-session-lw

API

functions exported by the module

functionargumentsdescription
thisoptions object (see next section)Initialize middle-ware
gcnonegarbage collector, you can call it explicitly
getSessionDatakey (user session key)fetch the session data object belonging to a session key
Initializing

const express = require('express');

var app = express();

const express_session_lw = require('express-session-lw');



app.use ( express_session_lw( options ) );
.
Options object properties
Property nameDescriptionDefault Value
debugWill show tracing/logging info via console.logfalse
globalTimeOutThe time for a session to be idle (no browser activity) before the session key is discarded30 (seconds)
garbageCollectgarbage collector interval to hoover up , timed out session keys500 (seconds)
sessionKeyNameThe name of the cookie to be used as session key"lw_session_id"
Basic usage

const express = require('express');

var app = express();

const express_session_lw = require('express-session-lw');

const session_middleware = express_session_lw({
    debug:false,          
     // clean up session keys that have been idle for 3 hours
    globalTimeOut:3600*3,
    // garbage collect timed-out session keys every 60 seconds
    garbageCollect: 60,
    // name of the cookie to hold the session key
    sessionKeyName:"__SESSION_LW"    
});

app.use(session_middleware);
Example use of garbage collector and session data fetch outside of express middleware.

// explicity call the garbage collector
express_session_lw.gc();
// fetch from global memory store,
// the session related storage object using the session key.
var session_data = express_session_lw.getSessionData( key );


Request.session_data

The object property session_data is automatically added to the request object, with the following properties

property nameDescription
keykey value as (string)
last_accessinteger unix timestamp of the last time this session key was used.
Adjust max idle time on a per session basis

Add the property timeout to the request object and will override globalTimeOut in the option object used to initialize the middleware

Adding data to the session:

Just add your own custom properties to the request.session_data object.

app.get("/login" , function (req, send, next) {
  ..
  ..
  // these properties always exist,
  console.log(req.session_data.key); // print out my session key
  console.log(req.session_data.last_access); // print out the last usage

  // add new session properties
  req.session_data.shopcart = [ 'item1', 'item2','item3'];
  ..
  ..
});

Keywords

FAQs

Package last updated on 12 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc