node Cookie

代码:

const express = require('express');

const cookieParser = require('cookie-parser');

const app = express();

 

app.use(cookieParser());

//用于显示cookie

app.get('/',function(req,res){

  res.send(req.cookies);

});

//用于添加cookie

app.get('/add',function(req,res){

  var name = req.query.name;

  var value = req.query.value;

  res.cookie(name,value);

  res.redirect('/');

})

app.get('/remove',function(req,res){

  var name = req.query.name;

  res.clearCookie(name);

  res.redirect('/');

});

app.listen(8000);

//网页传值的时候不能是中文,否则会报错

posted @ 2018-05-14 18:57  甜珊贝奇  阅读(117)  评论(0编辑  收藏  举报