strong-cluster-connect-store

Implementation of connect session store using node's native cluster messaging

npm install strong-cluster-connect-store
6 downloads in the last week
34 downloads in the last month

Connect Session Store for Cluster

Build Status NPM version

Overview

Strong-cluster-connect-store is an implementation of connect session store using node's native cluster messaging. It provides an easy way for using sessions in connect/express based applications running in a node cluster.

Features

  • Supports both connect and express.
  • No dependencies on external services.
  • Module is shipped without connect, it will use your version of connect or express.
  • Covered by unit-tests.

Usage

Installation

$ npm install strong-cluster-connect-store

Configuration - connect

var connect = require('connect');
var ClusterStore = require('strong-cluster-connect-store')(connect);

var app = connect();
app
  .use(connect.cookieParser())
  .use(connect.session({ store: new ClusterStore(), secret: 'keyboard cat' }));

Configuration - express

var express = require('express');
var ClusterStore = require('strong-cluster-connect-store')(express);

var app = express();
app
  .use(express.cookieParser())
  .use(express.session({ store: new ClusterStore(), secret: 'keyboard cat' }));

Setting up the master process

The store requires that a shared-state server is running in the master process. The server is initialized automatically when you require() this module from the master. In the case that your master and workers have separate source files, you must explicitly require this module in your master source file. Optionally, you can call setup() to make it more obvious why you are loading a module that is not used anywhere else.

// master.js

var cluster = require('cluster');
// etc.

require('strong-cluster-connect-store').setup();

// configure your cluster
// fork the workers
// etc.
}
npm loves you