This is a yet another session implementation for Node.js.
I know that there's a lot of Session modules for Node.js but I failed to find one like Cookies that was keep-it-simple and standalone.
Currently the module saves sessions to the filesystem but that should be changed to use some kind of plugable storing method.
PLEASE NOTE: By default this module uses
json-object AND it is poluting
standard global objects (hijacking .toJSON() etc). See
options.useStandardJSON
to disable this.
Simplest way to install is to use npm, just simply npm install yasession
.
MIT-style license, see INSTALL.txt.
require('http').createServer(function (req, res) {
var session = require('yasession')(req, res, {'dir':'/tmp'});
if(!session.date) session.date = new Date();
if(!session.counter) session.counter = 0;
session.counter++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\nThis is your ' + session.counter + " visit here after "+ session.date.toDateString() + ".");
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Standard Node.js HTTP/HTTPS request object.
Standard Node.js HTTP/HTTPS response object.
If true
then additional debug messages are printed with util.log
. Default is false
.
Cookie name. Default is YASESS
.
Optional domain setting for cookies.
Prefix for session files. Default is sess
.
Directory where to save JSON files. Default is ./tmp/cookies
.
By default yasession
is using
json-object to parse and
stringify JSON.
Please note: json-object
is poluting standard global objects (hijacking .toJSON() etc).
This can be changed by turning this option to false
.