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.