I am trying to create an HTTP server with cookie, but while executing the code, it returns me error, saying that the session is not defined.
My code :
//Initializing the modules
var http = require('http');
var connect = require('connect');
var cookieParser = require('cookie-parser');
var cookieSession = require('cookie-session');
var queryParser = require('express-query-int');
var format = require('util').format;
var app = connect();
// setup middleware
app.use(queryParser());
app.use(cookieParser('this is my secret string'));
app.use(session({
cookie: { maxAge: 24 * 60 * 60 * 1000 } //defines how long the session cookie can live in the browser before expiring.
}));
// actually respond
app.use(function(req, res) {
for (var name in req.query) {
req.session[name] = req.query[name];
}
res.end(format(req.session) + '\n');
});
http.createServer(app).listen(8080);
Error :
session is not defined
I saw in some documentations that using connect-session
is not more good to use, now we use express-session
, but how can I make that work ?
via Monteiro
No comments:
Post a Comment