在
fs.mkdir您删除会话后,听起来很异国。(我发现了您的其他问题)
但是回到问题,这里有一些代码片段,您可以使用会话(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
的示例
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)