litchi-cookie

A simple cookie management utility for NodeJs web applications

Usage no npm install needed!

<script type="module">
  import litchiCookie from 'https://cdn.skypack.dev/litchi-cookie';
</script>

README

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