{"id":17558,"library":"cookiefile","title":"Node.js Netscape HTTP Cookie File Parser","description":"The `cookiefile` package for Node.js provides utilities for reading, writing, and manipulating Netscape HTTP Cookie Files, a format commonly used by cURL and wget. It also supports parsing and generating `Set-Cookie` and `Cookie` HTTP headers for HTTP request and response contexts. The current stable version is 1.0.10, released in 2018. Due to its age, it does not support modern cookie directives such as `Max-Age` or `Same-Site`, which are crucial for contemporary web applications and security best practices. The package has seen no updates since 2018, indicating it is no longer actively maintained and may not be fully compatible with newer Node.js versions or evolving cookie specifications. Its primary utility lies in legacy systems or specific integrations requiring the exact Netscape cookie file format.","status":"abandoned","version":"1.0.10","language":"javascript","source_language":"en","source_url":"https://github.com/horat1us/node-cookiefile","tags":["javascript","libcurl","cookie","cookiefile","netscape","wget","file","header"],"install":[{"cmd":"npm install cookiefile","lang":"bash","label":"npm"},{"cmd":"yarn add cookiefile","lang":"bash","label":"yarn"},{"cmd":"pnpm add cookiefile","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package name is 'cookiefile', not 'http-cookiefile' as erroneously shown in older READMEs.","wrong":"const { Cookie } = require('http-cookiefile');","symbol":"Cookie","correct":"const { Cookie } = require('cookiefile');"},{"note":"Used for loading and managing collections of cookies, typically from a file or headers.","wrong":"const { CookieMap } = require('http-cookiefile');","symbol":"CookieMap","correct":"const { CookieMap } = require('cookiefile');"},{"note":"Custom error class for cookie-related operations.","wrong":"const { CookieError } = require('http-cookiefile');","symbol":"CookieError","correct":"const { CookieError } = require('cookiefile');"}],"quickstart":{"code":"import { Cookie, CookieMap } from 'cookiefile';\nimport * as fs from 'fs';\n\nasync function run() {\n  const cookieFilePath = 'my.cookiefile';\n\n  // 1. Create a new Cookie object\n  const myCookie = new Cookie({\n    domain: '.example.com',\n    name: 'session_id',\n    value: 'abc123def456',\n    https: true,\n    httpOnly: true,\n    crossDomain: false,\n    expire: Date.now() + (3600 * 1000) // Expires in 1 hour\n  });\n\n  // 2. Initialize a CookieMap and add the new cookie\n  const cookieMap = new CookieMap();\n  cookieMap.set(myCookie);\n\n  // 3. Simulate loading from an existing Netscape cookie file\n  // For this example, we'll create a dummy file first.\n  const dummyCookieFileContent = `# Netscape HTTP Cookie File\\n.google.com\\tFALSE\\t/\\tFALSE\\t0\\tPREF\\tabcde12345`;\n  fs.writeFileSync('temp.cookiefile', dummyCookieFileContent);\n\n  const loadedCookieMap = new CookieMap('temp.cookiefile');\n  console.log('Loaded cookies from file:');\n  loadedCookieMap.forEach((cookie, name) => console.log(` - ${name}: ${cookie.value}`));\n\n  // Add another cookie to the loaded map\n  loadedCookieMap.set(new Cookie({\n    domain: '.another.com',\n    name: 'user_token',\n    value: 'xyz987',\n    https: false,\n    httpOnly: false,\n    crossDomain: false,\n    expire: 0 // Session cookie\n  }));\n\n  // 4. Save the combined cookies to a new file\n  await loadedCookieMap.save(cookieFilePath);\n  console.log(`Cookies saved to ${cookieFilePath}`);\n\n  // 5. Generate HTTP Request/Response headers\n  const requestHeader = loadedCookieMap.toRequestHeader();\n  console.log('Generated Request Header:', requestHeader);\n\n  const responseHeader = loadedCookieMap.toResponseHeader();\n  console.log('Generated Response Header:', responseHeader);\n\n  // Clean up dummy file\n  fs.unlinkSync('temp.cookiefile');\n}\n\nrun().catch(console.error);","lang":"typescript","description":"This quickstart demonstrates how to create `Cookie` objects, initialize `CookieMap` from a file, add new cookies, save them to a Netscape format file, and generate HTTP `Cookie` and `Set-Cookie` headers."},"warnings":[{"fix":"Consider alternative, actively maintained cookie parsing libraries if possible, especially for new projects or those requiring full RFC compliance.","message":"The `cookiefile` package is abandoned, with its last commit in March 2018. It is not maintained for modern Node.js versions, security updates, or contemporary web standards. Using it in new projects is discouraged due to potential compatibility and security risks.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always use `require('cookiefile')` or `import { ... } from 'cookiefile'`.","message":"The README and some documentation incorrectly suggest importing from `'http-cookiefile'`. The correct package name for `require` or `import` is `'cookiefile'`. Using the wrong path will result in a 'Cannot find module' error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Developers must manually handle these directives if they are critical for their application. This limitation severely restricts its use in modern web development.","message":"This package explicitly does not support modern cookie directives such as `Max-Age` and `Same-Site`. Cookies using these directives will not be parsed or generated correctly, which can lead to unexpected behavior or security vulnerabilities in modern web environments.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change your import statement from `require('http-cookiefile')` to `require('cookiefile')`.","cause":"The package name is `cookiefile`, but the documentation (and common mistake) refers to `http-cookiefile`.","error":"Error: Cannot find module 'http-cookiefile'"},{"fix":"This is a known limitation of the library. You must either avoid using these directives or manually parse/generate them outside of this package's functionality. Consider using a different, more modern cookie library if these features are critical.","cause":"The library does not support the `Max-Age` or `Same-Site` cookie directives, as stated in its limitations.","error":"Cookie 'my_cookie' was not set with Max-Age or Same-Site attributes in generated header."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}