{"id":19874456,"url":"https://github.com/strongloop/strong-cluster-connect-store","last_synced_at":"2025-08-10T00:15:16.185Z","repository":{"id":9420729,"uuid":"11291401","full_name":"strongloop/strong-cluster-connect-store","owner":"strongloop","description":"Implementation of connect store using node's native cluster messaging","archived":false,"fork":false,"pushed_at":"2017-01-27T14:47:51.000Z","size":44,"stargazers_count":11,"open_issues_count":3,"forks_count":3,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-02T10:50:49.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/strongloop.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-09T19:09:23.000Z","updated_at":"2019-07-20T01:00:35.000Z","dependencies_parsed_at":"2022-09-16T14:02:04.443Z","dependency_job_id":null,"html_url":"https://github.com/strongloop/strong-cluster-connect-store","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/strongloop/strong-cluster-connect-store","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-cluster-connect-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-cluster-connect-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-cluster-connect-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-cluster-connect-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strongloop","download_url":"https://codeload.github.com/strongloop/strong-cluster-connect-store/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strongloop%2Fstrong-cluster-connect-store/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269656018,"owners_count":24454571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T16:23:23.630Z","updated_at":"2025-08-10T00:15:16.130Z","avatar_url":"https://github.com/strongloop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connect Session Store for Cluster\n\n[![Build Status](https://travis-ci.org/strongloop/strong-cluster-connect-store.png?branch=master)](https://travis-ci.org/strongloop/strong-cluster-connect-store)\n[![NPM version](https://badge.fury.io/js/strong-cluster-connect-store.png)](http://badge.fury.io/js/strong-cluster-connect-store)\n\n## Overview\n\nStrong-cluster-connect-store is an implementation of connect session store\nusing node's native cluster messaging. It provides an easy way for using\nsessions in connect/express based applications running in a node cluster.\n\nFeatures:\n\n- Supports both Connect and Express.\n- No dependencies on external services.\n- Module is shipped without connect, it will use *your* version of connect\n  or express.\n- Covered by unit-tests.\n\nSee also [API documentation](http://apidocs.strongloop.com/strong-cluster-connect-store/).\n\n## Installation\n\n```sh\n$ npm install strong-cluster-connect-store\n```\n\n## Use\n\n### Configuration - connect\n\n```js\nvar connect = require('connect');\nvar ClusterStore = require('strong-cluster-connect-store')(connect);\n\nvar app = connect();\napp\n  .use(connect.cookieParser())\n  .use(connect.session({ store: new ClusterStore(), secret: 'keyboard cat' }));\n```\n\n### Configuration - express\n\n```javascript\nvar express = require('express');\nvar ClusterStore = require('strong-cluster-connect-store')(express);\n\nvar app = express();\napp\n  .use(express.cookieParser())\n  .use(express.session({ store: new ClusterStore(), secret: 'keyboard cat' }));\n```\n\n### Setting up the master process\n\nThe store requires that a shared-state server is running in the master process.\nThe server is initialized automatically when you require() this module\nfrom the master. In the case that your master and workers have separate source\nfiles, you must explicitly require this module in your master source file.\nOptionally, you can call `setup()` to make it more obvious why you are loading\na module that is not used anywhere else.\n\n```javascript\n// master.js\n\nvar cluster = require('cluster');\n// etc.\n\nrequire('strong-cluster-connect-store').setup();\n\n// configure your cluster\n// fork the workers\n// etc.\n}\n```\n\n### Using Strong Cluster Connect Store\n\nThe following example assumes you have set up Strong Cluster Connect Store for Express and have run the steps above.\n\n```javascript\n'use strict';\nvar express = require('express');\nvar cluster = require('cluster');\nvar numCPUs = require('os').cpus().length;\nvar ClusterStore = require('strong-cluster-connect-store')(express.session);\n\nif (cluster.isMaster) {\n  // The cluster master executes this code\n\n  ClusterStore.setup();\n\n  // Create a worker for each CPU\n  for (var i=0; i\u003cnumCPUs; i++) {\n    cluster.fork();\n  }\n\n  cluster.on('online', function(worker) {\n    console.log('Worker ' + worker.id + ' is online.');\n  });\n\n  cluster.on('exit', function(worker, code, signal) {\n    console.log('worker ' + worker.id + ' died with signal',signal);\n  });\n} else {\n  // The cluster workers execute this code\n\n  var app = express();\n  app.use(express.cookieParser());\n\n  app.use(express.session(\n    { store: new ClusterStore(), secret: 'super-cool' }\n  ));\n\n  app.get('/hello', function(req, res) {\n    var msg;\n    if (req.session.visited)\n      msg = {msg: 'Hello again from worker '+cluster.worker.id};\n    else\n      msg = {msg: 'Hello from worker '+cluster.worker.id};\n\n    req.session.visited = '1';\n    res.json(200, msg);\n  });\n  app.listen(8080);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-cluster-connect-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrongloop%2Fstrong-cluster-connect-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrongloop%2Fstrong-cluster-connect-store/lists"}