1

So I've been reading through some older SO posts and it seems that setting cookie values via express is a mess since the part of the lib one needs to modify cookies is now available as middle-ware and not part of the original but I can't really find any good documentation on the matter. These posts are all from ~2013.

Is there a new way to set the value of a cookie that works in Node?

This is for a web-scaper.

I've tried Cookies, Express, and CookieParser, all to no avail. At this point I don't know if its me doing something wrong or something else.

All I want to do is set a cookie with a specific name to a specific value.

I've been able to do this in CasperJS/PhantomJS with:

phantom.addCookie({
  'name': 'Added-Cookie-Name',
  'value': 'Added-Cookie-Value',
  'domain': 'domain url'
});

but I haven't found a similar way to do it successfully in Node.

Could anyone post a simple example for any method they know of that currently works in Node?

A B
  • 65
  • 1
  • 9
  • Possible duplicate of [How to set cookie value in Node.js?](http://stackoverflow.com/questions/12240274/how-to-set-cookie-value-in-node-js) – SteveLacy Apr 15 '16 at 00:10
  • Considering OP directly addresses the old questions not being useful for his purposes, I don't feel like that question is a duplicate. – Conspicuous Compiler Apr 15 '16 at 00:34
  • That said, if you're building an Express app, you could be able to directly set a cookie by [calling `cookie()` on the `res` object](http://expressjs.com/en/api.html#res.cookie). – Conspicuous Compiler Apr 15 '16 at 00:35
  • Do you know if that'd be possible when loading a site with cheerio? – A B Apr 15 '16 at 01:37
  • Does this answer your question? [Get and Set a Single Cookie with Node.js HTTP Server](https://stackoverflow.com/questions/3393854/get-and-set-a-single-cookie-with-node-js-http-server) – Antoni Jul 06 '20 at 14:25

0 Answers0