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?

5
  • Possible duplicate of How to set cookie value in Node.js? Commented Apr 15, 2016 at 0:10
  • Considering OP directly addresses the old questions not being useful for his purposes, I don't feel like that question is a duplicate. Commented Apr 15, 2016 at 0: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. Commented Apr 15, 2016 at 0:35
  • Do you know if that'd be possible when loading a site with cheerio? Commented Apr 15, 2016 at 1:37
  • Does this answer your question? Get and Set a Single Cookie with Node.js HTTP Server Commented Jul 6, 2020 at 14:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.