Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>it sounds very exotic, that after <code>fs.mkdir</code> your session erased. (I found your other SO question)</p> <p>But back to the question, here's a little code snippet how you can use sessions (redis).</p> <pre><code>var express = require('express') , fs = require('fs') , http = require('http') , RedisStore = require('connect-redis')(express) , sessionStore = new RedisStore() , app = express() ; app.configure(function(){ app.set('port', 3000); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('secret')); app.use(express.session({ store: sessionStore })); app.use(express.static(__dirname + '/public')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.get( '/', function(req, res){ res.setHeader("Content-Type", "text/html"); console.log( req.session ); console.log( '------------------------' ); res.end( 'root' ); }); app.get( '/dir/:id', function(req, res){ console.log( req.session ); console.log( '------------------------' ); fs.mkdir( req.params.id ); if ( req.session.dirs === undefined ) req.session.dirs = []; req.session.dirs.push( req.params.id ); console.log( req.session ); console.log( '------------------------' ); res.setHeader("Content-Type", "text/html"); res.end( 'dir' ); }); server = http.createServer(app).listen(3000); </code></pre> <p>you should read the docs of <a href="http://expressjs.com" rel="nofollow">express</a>, and browse the <a href="https://github.com/visionmedia/express/tree/master/examples/session" rel="nofollow">examples</a> of express</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload