84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
通过Google搜出来的结果有https://github.com/pillarjs/cookieshttps://github.com/expressjs/cookie-parserhttps://github.com/expressjs/cookie-session
把我搞混了,我现在需要的功能是检测cookie,设置session。 也就是常规的判断seesion状态,如果无seesion,登录后设置cookie这样一个功能,有没有简单的demo实现?
光阴似箭催人老,日月如移越少年。
我是这样用的:
//... var cookieParser = require('cookie-parser'); var session = require('express-session'); //... app.use(cookieParser()); app.use(session({ key: 'session', secret: 'keyboardcat', store: new MongoStore({ mongooseConnection: mongoose.connection }) })); //... router.get('/login', function(req, res, next) { // 读取 cookie var user = req.session.user; if (user) { return res.redirect('/'); } //.. }); router.post('/login', function(req, res, next) { //... // 设置 cookie req.session.user = user; return res.redirect('/'); });
express实例
demo:http://www.hubwiz.com/course/549a704f88dba0136c371703/,这是个nodejs+mongodb的实战的demo,里面有session的设置。
我是这样用的:
express实例
demo:http://www.hubwiz.com/course/549a704f88dba0136c371703/,这是个nodejs+mongodb的实战的demo,里面有session的设置。