Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

persistant cookies using nodejs

persistant cookies using nodejs

Problem

I want to save some cookies in my browser using node.js. Any one knows how I can achieve this behavior? My purpose is when the user has checked the checkbox("keep me logged in") then the checkbox state and the cookies should be stored.

Problem courtesy of: Ali Hassan

Solution

User jQuery cookie plugin

Create session cookie:

$.cookie('the_cookie', 'the_value');

Create expiring cookie, 7 days from then:

$.cookie('the_cookie', 'the_value', { expires: 7 });

Create expiring cookie, valid across entire site:

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/' });

Read cookie:

$.cookie('the_cookie'); // => "the_value"
$.cookie('not_existing'); // => null

Delete cookie:

// Returns true when cookie was found, false when no cookie was found...

$.removeCookie('the_cookie');

// Same path as when the cookie was written...

$.removeCookie('the_cookie', { path: '/' });
Solution courtesy of: Anshu

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

persistant cookies using nodejs

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×