Create cookie by name, value and days - Node.js Environment

Node.js examples for Environment:Cookie

Description

Create cookie by name, value and days

Demo Code


function createCookie(name, value, days) { 
  var expires; /*from   w  ww .ja v a  2 s . c o  m*/
  if (days) { 
    var date = new Date(); 
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 
    expires = "; expires=" + date.toGMTString(); 
  } 
  else expires = ""; 
  document.cookie = name + "=" + value + expires + "; path=/"; 
}

Related Tutorials