后端cookie-parser/前端cookies使用

//参考链接https://segmentfault.com/a/1190000004139342?_ea=504710
//后端示例

// npm install cookie-parser
var express      = require('express')
var cookieParser = require('cookie-parser')
 
var app = express()
app.use(cookieParser())
 
app.get('/', function(req, res) {
  console.log('Cookies: ', req.cookies)
})
 //cookie的创建(存储到cookie中) res.cookie(name, value [, options])
//cookie的读取  req.cookies/req.cookies.name
//cookie的删除res.clearCookie(name [, options])

app.listen(8080)

//前端示例

//通过 document.cookie 属性,可以创建、维护和删除 cookie
//document.cookie="name=Nicholas;domain=nczonline.net;path=/";

你可能感兴趣的:(后端cookie-parser/前端cookies使用)