Setting up persistence.js using

Installing persistence.js on node is easy using npm:

npm install persistencejs

Alternatively, you can clone the repository manually:

git clone git://

If installed manually, you also need to install node-mysql, the MySQL driver that the persistence store depends on.


You need to require two modules, the persistence.js library itself and the store module.

var persistence = require('persistencejs/persistence').persistence;
// For MySQL:
var persistenceStore = require('persistencejs/');
// For SQLite:
var persistenceStore = require('persistencejs/');

Alternatively, if you cloned persistence.js using git, use a relative path to the modules instead, e.g.:

var persistence = require('./persistencejs/persistence').persistence;
var persistenceStore = require('./persistencejs/');
// or
var persistenceStore = require('./persistencejs/');

Then, you configure the database settings to use:

// MySQL
persistenceStore.config(persistence, 'localhost', 3306, 'dbname', 'username', 'password');
// SQLite
persistenceStore.config(persistence, __dirname + '/mydb.db');

Subsequently, for every connection you handle (assuming you’re building a sever), you call the persistenceStore.getSession() method:

var session = persistenceStore.getSession();

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *