V
V
Vyacheslav Lebedev2015-02-19 15:13:21
Node.js
Vyacheslav Lebedev, 2015-02-19 15:13:21

How to work with cookies in nodejs?

Good afternoon! :)
Tell me how to work with cookies in a node?
Cookies are already stored in cookie, you need to count them and parse them by key: value, and how to work with all this?
In jQuery I do this:

var cook = JSON.parse($.cookie("cook"));
for (var key in cook) { 
  console.log(cook[key].field);
 }

And I get the field values. :)
How can I do something similar in node?
Here I need to organize the receipt of cookies and their processing:
app.post('/', function (req, res) { ... }
Thank you! :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Pasyuta, 2016-02-03
@slavikse

app.post('/', function (req, res) { ... }
this means you are (most likely) using express.
If yes, then use this cookie-parser
Like mine in index.js

var cookieParser = require('cookie-parser');
...
app.use(cookieParser());

and then in the controller you will have something like this
app.post('/', function(req, res) {
  console.log("Cookies: ", req.cookies)
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question