Created
July 11, 2016 02:09
-
-
Save LincolnBurrows/1604cde4a47bcff3e1f8f8037e310c56 to your computer and use it in GitHub Desktop.
cookie-parser module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var cookieParser = require('cookie-parser'); | |
var app = express(); | |
app.use(cookieParser); | |
app.get('/', function(req, res){ | |
// 如果请求中的 cookie 存在 isVisit, 则输出 cookie | |
// 否则,设置 cookie 字段 isVisit, 并设置过期时间为1分钟 | |
if(req.cookies.isVisit){ | |
console.log(req.cookies); | |
res.send('hello'); | |
} else{ | |
res.cookie('isVisit', 1, {maxAge:60*1000}); | |
res.send('first visit!'); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
语法: response.cookie('cookieName', 'name=value[name=value...]',[options]);