Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:10+00:00 2026-06-16T00:11:10+00:00

I feel quite confused, do not understand what is the difference between res.cookie and

  • 0

I feel quite confused, do not understand what is the difference between res.cookie and req.cookies. And more strangely, I have found that if I do not set a cookie:

//The value will be:
req.cookies.uid=="undefined"
//instead of:
req.cookies.uid==undefined

Why the express.js design the cookie like this?

If I want to implement a “remember me” function while users trying to log in and set the cookie expire time to infinite or maybe a year, how should I use the cookie correctly?

I have found that the cookieParser only support thing like this:

express.cookieParser("secret")

And does not support expire/maxAge setting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:11:11+00:00Added an answer on June 16, 2026 at 12:11 am

    res.cookie is actually a function with a signature of res.cookie(key, value, opts). You can use it to set a client’s cookie values/options. On the other hand, req.cookies is an object that gives you the client’s current cookie values. Here’s an example using cookies to track page views:

    var counter = 0;
    app.get('/counter', function(req, res) {
        res.cookie('counter', ++counter);
    
        if (!req.cookies.counter) {
            res.send('This is your first visit!');
        } else {
            res.send('This is visit number '+ req.cookies.counter +'!');
        }
    });
    

    If you use the express.cookieSession() middleware, you can set application wide default cookie properties. For example, the cookie’s maxAge property determines how many milliseconds in the future the cookie will expire, so here I set it to expire in one hour:

    app.use(express.cookieParser());
    app.use(express.cookieSession({ secret: 'secret', cookie: { maxAge: 60 * 60 * 1000 }});
    // ... your middleware and routes
    

    Otherwise, you could set the cookie options individually by passing an options object to res.cookie().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this is quite delicate, I have various folders whith projects I
I've been looking around for quite a while and feel that I have a
My one activity seems to have grown quite a bit and I feel like
I have a question that may be quite naive, but I feel the need
I feel like I could do something with linked lists, but I'm not quite
I am trying to get a feel for the difference between the various classes
I am quite new to client-side web development, so just feel free to edit
I feel like I am not writing this correctly and this is my first
I feel quite overwhelmed with the variety on technologies I would need to use
I come from SML background and feel quite comfortable with high-order functions. But I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.