{"library":"node-cookie","title":"Node.js HTTP Cookie Management","description":"node-cookie is a utility library for Node.js environments, designed to simplify the parsing, signing, encryption, creation, and clearing of HTTP cookies. It directly interfaces with Node.js's built-in `http.IncomingMessage` and `http.ServerResponse` objects, making it agnostic to higher-level web frameworks. The current stable version is 2.1.2, which was last published over six years ago. Despite some recent activity on its GitHub repository (commits in 2022-2023), the package itself has not seen new releases, suggesting it is in an abandoned or very low-maintenance state. Its key differentiator is providing low-level, built-in cookie signing and encryption capabilities without requiring a full framework or complex middleware, directly leveraging Node.js crypto primitives.","language":"javascript","status":"abandoned","last_verified":"Wed Apr 22","install":{"commands":["npm install node-cookie"],"cli":null},"imports":["import nodeCookie from 'node-cookie'","import nodeCookie from 'node-cookie'; nodeCookie.create(res, 'key', 'value')","const nodeCookie = require('node-cookie'); const cookies = nodeCookie.parse(req)","const nodeCookie = require('node-cookie'); const value = nodeCookie.get(req, 'key')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const http = require('http');\nconst nodeCookie = require('node-cookie');\n\nconst SECRET = process.env.COOKIE_SECRET ?? 'supersecretkeyfornodejsapp';\n\nhttp.createServer(function (req, res) {\n  if (req.url === '/set-cookie') {\n    // Create a signed and encrypted cookie\n    nodeCookie.create(res, 'userSession', 'user123', { expires: new Date(Date.now() + 60 * 60 * 1000) }, SECRET, true);\n    nodeCookie.create(res, 'lastVisit', new Date().toISOString(), SECRET, false);\n    res.writeHead(200, { 'Content-Type': 'text/plain' });\n    res.end('Cookies set!');\n  } else if (req.url === '/get-cookie') {\n    // Parse and retrieve cookies\n    const parsedCookies = nodeCookie.parse(req, SECRET, true);\n    const userSession = nodeCookie.get(req, 'userSession', SECRET, true);\n    const lastVisit = nodeCookie.get(req, 'lastVisit', SECRET, false);\n\n    res.writeHead(200, { 'Content-Type': 'application/json' });\n    res.end(JSON.stringify({\n      parsedCookies,\n      userSession: userSession || 'Not found or invalid',\n      lastVisit: lastVisit || 'Not found or invalid'\n    }));\n  } else {\n    res.writeHead(200, { 'Content-Type': 'text/html' });\n    res.end('<h1>Visit /set-cookie to set, or /get-cookie to retrieve.</h1>');\n  }\n}).listen(3000, () => {\n  console.log('Server running on http://localhost:3000');\n  console.log('Try http://localhost:3000/set-cookie then http://localhost:3000/get-cookie');\n});","lang":"javascript","description":"This quickstart demonstrates setting and retrieving signed and encrypted HTTP cookies using `node-cookie` with a basic Node.js HTTP server. It shows `create` for writing cookies with options for expiration, signing, and encryption, and `parse` and `get` for reading them, also handling decryption and unsigning.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}