Cookie-parser's role, the official argument is: The Parse header and populate with a Cookie req.cookies object keyed by the cookie names. my understanding is to convert the cookies in headers and merge them with Req.cookies. As the core of Cookie-parser, parser hints at 2 functions:signedcookies and Jsoncookies, and their helper functions. This article to the end of this plugin, let us review, but also opened the next session on the study. Cookie-parser takes a cookie from the client and then passes the Express-session (Express-based) processing. After the client is represented as a signed string, on the server side, because of the use of the Unsign method, you can see the checked characters. In this way, all the fans are untied. Let's take a look at the code of the session that deals with cookies. function Setcookie (res, name, Val, secret, options) { var signed = ' s: ' + Signature.sign (Val, secret); //.... Omit res.setheader (' Set-cookie ', header)} Here write cookies with Set-cookie. When the client sends a cookie, the Parser.js signedcookies is used. exports.signedcookies = function (obj, secret) { var cookies = Object.keys (obj); var dec; & nbsp var key; var ret = object.create (null); var val; for (var i = 0; i < cookies.length; i++) {&nbs P key = cookies[i]; val = Obj[key]; Dec = Exports.signedcookie (val, secret); if (Val!== Dec) {  ; Ret[key] = dec; Delete obj[key]; } } return ret;} ; exports.signedcookie = function (str, secret) { return Str.substr (0, 2) = = = ' s: ' ? Signatur E.unsign (Str.slice (2), secret) : str;}; In the Help function Signedcookie, when the discovery contains S: Start is the signed CoOkie, then used the signature.unsign to sign. Next time, let's take a look at the session.
[Cookie]cookie-parser parser.js