Sending and Receiving Cookies
The cookie-parser
middleware provided in Express makes handling cookies extremely simple. The cookie-parser
middleware parses the cookies from a request and stores them in the req.cookies
property as a JavaScript object. The cookie-parser
middleware uses the following syntax:
express.cookie-parser([secret])
Note
The cookie-parser
middleware will be renamed cookie
when Connect 3.0 ships. You may need to change your code to support the new name if it doesn’t end up being backward compatible.
The optional secret
string parameter prevents cookie tampering by internally signing the cookies using the secret
string.
To set a cookie in a response, you can use the res.cookie()
method shown ...
Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.