Skip to content

Conversation

@hematy61
Copy link
Contributor

I have updated the doc to show how multiple key values for a cookie can be set.

I have updated the doc to show how multiple key values for a cookie can be set.
@wesleytodd
Copy link
Member

Hey @hematy61, I am interested in what this adds which is not covered or clear with the existing docs? Was it unclear from the existing docs how to do this?

@hematy61
Copy link
Contributor Author

Hey @wesleytodd. thanks for asking. I didn't find anything mentioning how to add more than one key value to a cookie. is there any? if there is, shouldn't it be mentioned here as well?

@wesleytodd
Copy link
Member

add more than one key value to a cookie

Not sure what you mean by this. A cookie can have only one value. In your example you are just adding two separate cookies, which is basically the same code as the example above:

res.cookie('name', 'tobi', { domain: '.example.com', path: '/admin', secure: true })
res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true })

I was just wondering if that code snippet is not enough to illustrate the point. If not, I could see maybe using the same code block and adding to the paragraph above it a point about "this example sets two cookies in one response" or something to that effect. Make sense?

@hematy61
Copy link
Contributor Author

I see what you mean. In the beginning, I was confused about how I can set 2 or more key values in one request. technically,

res.cookie( 'key1', 'value1')
res.cookie( 'key2', 'value2')
res.send()

is the same as chaining them together like:

res.cookie( 'key1', 'value1')
      .cookie( 'key2', 'value2')
      .send()

but for someone who doesn't know chaining is working here, it's gonna be confusing (as it was for me). I had to search to see how I can add multiple key values in one response. I hope my point makes sense now.

@wesleytodd
Copy link
Member

That makes way more sense to me now. I think a great addition would be to show that you can do either of those with a single line of "You can set multiple cookies in a single response by calling res.cookie multiple times, for example:"...

@hematy61
Copy link
Contributor Author

Right on. that's it. And I have modified it with what you have suggested.

@wesleytodd
Copy link
Member

Looks fine to me now. Just needs formatting cleanup, use two space indentation, single quotes, and no semicolons (sorry for the nitpicks, but gotta keep things consistent with the formatting guidelines moving forward!).

@crandmck do you have opinions on this addition?

@hematy61
Copy link
Contributor Author

No worries. it should be good now.

@hematy61
Copy link
Contributor Author

shouldn't we close it?

@hematy61 hematy61 changed the title Update res.cookie for multiple key values Update res.cookie for setting multiple cookies in a single response Aug 31, 2019
@crandmck
Copy link
Member

crandmck commented Sep 5, 2019

LGTM... Thanks for the contribution!

@crandmck crandmck merged commit efe692c into expressjs:gh-pages Sep 5, 2019
krzysdz added a commit to krzysdz/expressjs.com that referenced this pull request Apr 25, 2025
bjohansebas pushed a commit that referenced this pull request May 1, 2025
* Include 4.18 API doc updates in 5.x

5c98ee4

Co-authored-by: Douglas Christopher Wilson <[email protected]>

* Copy acceptsLanguages documentation improvements to 5.x

#1402

Co-authored-by: Jon Ege Ronnenberg <[email protected]>

* Add warning boxes to {app,res}.render

5e918ea

Co-authored-by: Douglas Christopher Wilson <[email protected]>

* Copy warning around securing locals to 5.x

fcaca7f

Co-authored-by: Douglas Christopher Wilson <[email protected]>

* Copy res.cookie `partitioned` option docs

#1456

Co-authored-by: Rich Hodgkins <[email protected]>

* Update req.body to point to built-in middleware

a5ca5b0

Co-Authored-By: Douglas Wilson <[email protected]>

* Copy setting multiple cookies example to 5.x

#1063

Co-Authored-By: Mo <[email protected]>

---------

Co-authored-by: krzysdz <[email protected]>
Co-authored-by: Douglas Christopher Wilson <[email protected]>
Co-authored-by: Jon Ege Ronnenberg <[email protected]>
Co-authored-by: Rich Hodgkins <[email protected]>
Co-authored-by: Mo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants