Set Client-Side Accessible Cookie In Express

Figured it out! By default Express sets the option httpOnly to true. This means that your cookies cannot be accessed by the client-side Javascript. In order to correctly set cookies accessible on the client just use a snippet like the following:

res.cookie('rememberme', 'yes', { maxAge: 900000, httpOnly: false});

I’ve also noticed that if you call this command and then call res.redirect, the cookie won’t get set. This command needs to be followed by res.render at some point in order for it to work. Not sure why this is.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)