2K01B5
2K01B5

Reputation: 1121

How to set a cookie age without using a framework in Node.js?

I cannot find any information on setting the age of a cookie without using an external module. I know how to set the cookie but not its age and want to do it without the use of a library.

Any help would be much appreciated.

Upvotes: 1

Views: 682

Answers (2)

Muhammad Usman
Muhammad Usman

Reputation: 10148

response.writeHead(200, {
'Set-Cookie':'sesh=wakadoo; expires='+new Date(new Date().getTime()+86409000).toUTCString()
});

This will set the expiry date of 1 day for the cookie

Upvotes: 3

RidgeA
RidgeA

Reputation: 1546

//....
response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
//....

https://nodejs.org/api/http.html#http_response_setheader_name_value

Upvotes: 0

Related Questions