litchi-cookie

0.0.2 • Public • Published

litchi-cookie

A simple cookie management utility for NodeJs web applications

NPM Version NPM Downloads Node.js Version

how to use?

npm install litchi-cookie
'use strict';
 
var PORT = 8082;
var http = require('http');
var Cookie = require('litchi-cookie');
 
http.createServer(function (req, res) {
  
  req.on('end', function() {
    try {
      var objCookie = new Cookie(req, res);
 
      //set cookie with name and value 
      objCookie.set('abc', 'def');
      res.write("\nCookie set abc");
 
      var strCookieValue = objCookie.get('abc');
      res.write('\nCookie get abc, value: ' + strCookieValue);
    } catch(e) {
      console.log(e);
    }
 
    res.statusCode = 200;
    res.end("\nHello World");
  });
}).listen(process.env.PORT || PORT);
 
console.log('Server running at http://localhost:' + (process.env.PORT || PORT));

more options

The set function has an optional third parameter as object to set cookie more options as follows: maxAge : max age of the cookie in seconds domain : domain for the cookie path : cookie path expires : expiration date for the cookie secure : true or false httpOnly : true or false firstPartyOnly : true or false

License

MIT

Package Sidebar

Install

npm i litchi-cookie

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • deepeshs