代码:
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);
//网页传值的时候不能是中文,否则会报错