在express(node.js)和neo4j数据库上存储会话

时间:2014-12-26 10:11:29

标签: node.js express neo4j

我正在寻找使用node.js,express和neo4j作为数据库来存储我的会话。如何将会话存储在内存中?我正在寻找一种方法来存储我的会话neo4j数据库或替代

 var express = require('express');
var path = require('path');

var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');

var routes = require('./routes/index');


var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true,
  cookie: {maxAge:86400000, secure: true}
}));
. 
. 
.

2 个答案:

答案 0 :(得分:1)

嘿,Redis可能是一个解决方案,但我确实希望在本地存储我的会话,所以我使用了sessionStore它非常棒且非常容易实现。

var session = require('express-session');

var sessionstore = require('sessionstore');

var routes = require('./routes/index');


var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));


app.use(session({
  store:sessionstore.createSessionStore(),
  secret: 'this is the big secret every body is fussing abt',
  resave: false,
  saveUninitialized: true
}));

答案 1 :(得分:-1)

使用An advanced session store for Redis for node.js

这很容易集成到您的系统中。