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

164
Views
how to update a cookie using nodejs

I set cookie using the below code,

app.get("/", (req, res) => {
  let options = {
    maxAge: 1000 * 60 * 15, // would expire after 15 minutes
    httpOnly: true, // The cookie only accessible by the web server
  };

  let userData = {
    name: "John",
    age: 23,
  };

  // Set cookie
  res.cookie("cookieName", userData, options); // options is optional
  res.send("done");
});

Read the cookie using,

app.get("/get", function (req, res) {
  // read cookies
  res.send(req.cookies["cookieName"]);
});

I need to update the value in the cookie, need to change age:23 to age:32. How can I update the cookie?

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

0

let userData = {
    name: "John",
    age: 32,
  };      
res.cookie("cookieName", userData, options); // options is optional

same code will work for update part, if key name is same, if key name is different it'll create new key in cookie

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!