use database to store session in express framework
use MySQL to store session in express framework
Install express-mysql-session
npm install express-mysql-session
how to use mysql session in express framework ?
var express = require('express');
var app = module.exports = express();
var session = require('express-session');
var MySQLStore = require('express-mysql-session')(session);
var options = {
host: 'localhost',
port: 3306,
user: 'session_test',
password: 'password',
database: 'session_test'
};
var sessionStore = new MySQLStore(options);
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: sessionStore,
resave: true,
saveUninitialized: true
}));
use MongoDB to store session in express framework
Install express-session-mongo
npm install https://github.com/trottski/express-session-mongo/archive/master.tar.gz
how to use MongoDB to store session in express framework ?
var xp = require('express'),
MongoStore = require('express-session-mongo');
var app = xp.createServer();
app.configure(function(){
app.use(xp.cookieDecoder());
app.use(xp.session({ store: new MongoStore() }));
app.use(app.router);
});