这听起来很异国情调,在fs.mkdir
你的会议被抹去之后。(我发现了你的另一个 SO 问题)
但回到这个问题,这里有一个小代码片段,你可以如何使用会话(redis)。
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);
您应该阅读express的文档,并浏览express的示例