An express-session store for Sequelize.js
Last updated 3 years ago by mattmcfarland .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install sequelstore-connect 
SYNC missed versions from official npm registry.

An express-session store for Sequelize.js

npm Travis Coverage Status

Sequelize session store for Connect and Express


  • Support Express 4.x and 5.0
  • Support Node.js 0.10, 0.12, 4.x, 5.x and all io.js versions
  • Support for Sequelize up to version 3.15

Express or Connect integration

Express 4.x, 5.0 and Connect 3.x:

const session = require('express-session');
const SequelStore = require('sequelstore-connect')(session);

    secret: 'foo',
    store: new SequelStore(options)

Connection to Sequelize

sequelstore-connect can be used in three different ways, depending on your architecture, you should pick one which fits your requirements and architecture the best.

  • Usage with your existing database by adding a specific model.

  • Usage with your existing database by passing a custom model into it.

  • Or it can create the model for you.

const Sequelize = require('sequelize');

// Basic usage
const database = new Sequelize(config);

    store: new SequelizeStore({database})

Re-use your Sequelize instance.

In this case, you just have to give your Db instance to sequelstore-connect. If the connection is not opened, sequelstore-connect will do it for you.

** There are many ways to create an instance.
** You should refer to the ORM documentation

const database = require ('./models').sequelize;

    store: new MongoStore({ database })

Using your own session models

Automatically use your db by creating a Model named ConnectSession

 * IF this model exists anywhere in your db then
 * it will be used for session storage. It must be named "ConnectSession"
module.exports = (sequelize, DataTypes) => {
  return sequelize.define('ConnectSession', {
    sid: {
      type: DataTypes.STRING,
      primaryKey: true
    expires: DataTypes.DATE

Using a custom session model

Use the sessionModel option for custom integration.

store = new SequelStore({
  sessionModel: db.models.FooModel

Session expiration

When the session cookie has an expiration date, sequelstore-connect will use it.

Otherwise, it will create a new one, using ttl option.

    store: new MongoStore({
      database: db,
      ttl: 14 * 24 * 60 * 60 // = 14 days. Default

Note: Each time an user interacts with the server, its session expiration date is refreshed.

Remove expired sessions

Expired session are removed from the database every 15 minutes by default. You can change it by setting autoRemoveInterval

    store: new MongoStore({
      autoRemoveInterval: 15 * 60 * 1000 // = 15 minutes. Default.

Disable expired sessions cleaning

You are in production environment and/or you manage the TTL index elsewhere.

    store: new MongoStore({
      url: 'mongodb://localhost/test-app',
      autoRemoveInterval: 0

More options

  • fallbackMemory Fallback to MemoryStore. Useful if you want to use MemoryStore in some case, like in development environment.
  • transform Default is JSON.stringify - you can change the function that handles the session data.


npm install && npm test


After cloning this repo, ensure dependencies are installed by running:

npm install

This library is written in ES6 and uses Babel for ES5 transpilation and Flow for type safety. Widely consumable JavaScript can be produced by running:

npm run build

Once npm run build has run, you may import or require() directly from node.

After developing, the full test suite can be evaluated by running:

npm test

While actively developing, we recommend running

npm run watch

in a terminal. This will watch the file system run lint, tests, and type checking automatically whenever you save a js file.

To lint the JS files and run type interface checks run npm run lint.


The following sources were heavily studied and/or used to product this library.


The MIT License

Current Tags

  • 1.1.5                                ...           latest (3 years ago)

12 Versions

  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 12
Last Day 0
Last Week 12
Last Month 0
Dependencies (0)
Dev Dependencies (32)
Dependents (2)

Copyright 2014 - 2017 © |