// 获得客户端的Cookie
var
Cookies = {};
req.headers.cookie && req.headers.cookie.split(
';'
).forEach(
function
( Cookie ) {
var
parts = Cookie.split(
'='
);
Cookies[ parts[ 0 ].trim() ] = ( parts[ 1 ] ||
''
).trim();
});
console.log(Cookies)
// 向客户端设置一个Cookie
res.writeHead(200, {
'Set-Cookie'
:
'myCookie=test'
,
'Content-Type'
:
'text/plain'
});
res.end(
'Hello World
'
);
=======
var date=new Date(); date.setTime(date.getTime()+30*60*1000); //设置date为当前时间+30分 document.cookie="key=value; expires="+date.toGMTString(); //将date赋值给expires