Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
encode object into cookie string for testing

I'm using cookies to pass the session about the logged in user, and on the server I can set and get them fine:

res.cookie("foo", { bar: "baz" })

// later on
console.log(req.cookies.foo) // { bar: "baz" }

Now, I want to test it, and I need to set the cookie header, but I don't know how to convert an object, i.e. { bar: "baz" }, to the header string the cookie evaluates to enter image description here

What's the algorithm used here?

(I'm using supertest but it shouldn't matter IMO)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In express by default the cookie is encoded, you need to pass the options to keep it as a string.

encode Function - A synchronous function used for cookie value encoding. Defaults to encodeURIComponent.

// Custom encoding
res.cookie("foo", { bar: "baz" }, {encode: String})

You can check here for more details.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!