D
D
Denis2018-02-09 22:02:48
Node.js
Denis, 2018-02-09 22:02:48

How to write two identical parameters in NodeJS server response headers?

I want to create cookies for the user, so I send him the Set-cookie header: Great, one cookie is set, but how can I set two cookies in one response? When trying to write something like:
res.setHeader('Set-cookie', 'a=4');

res.setHeader('Set-cookie', 'a=4');
res.setHeader('Set-cookie', 'b=5');

I don't get the desired result because one header overlaps the other. I also tried to do the same with writeHead, but as you can guess it didn't work either, only the last header is set.
Please let me know if there is a solution to this problem. In php, of course, this is easier, I called setCookie twice, sent two cookies and there are no problems.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-02-10
@yellow79

res.setHeader('Set-cookie', 'a=4; b=5; c=6');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question