{"library":"node-fetch-cookies","title":"node-fetch-cookies","description":"node-fetch-cookies is a wrapper around the popular `node-fetch` library, specifically designed to add robust support for HTTP cookie management in Node.js environments. It enables developers to easily handle cookie-jars, allowing for persistent session management across multiple requests. The library supports both in-memory cookie storage and file-based persistence using JSON files, minimizing disk I/O by only saving when explicitly instructed. As of version 2.1.1, the project is actively maintained, addressing recent bug fixes related to redirect handling and cookie attribute parsing. It primarily targets modern Node.js environments (>=14.13.0) and leverages ES Modules for its primary usage patterns. Its key differentiators include simplified cookie persistence and re-exporting core `node-fetch` components, providing a familiar API while adding essential cookie functionality.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-fetch-cookies"],"cli":null},"imports":["import { fetch } from 'node-fetch-cookies';","import { CookieJar } from 'node-fetch-cookies';","import { nodeFetch } from 'node-fetch-cookies';","import { Headers } from 'node-fetch-cookies';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { fetch, CookieJar } from \"node-fetch-cookies\";\nimport { promises as fs } from 'fs';\n\n(async () => {\n    const jarFilePath = \"jar.json\";\n\n    // Create a CookieJar instance\n    const cookieJar = new CookieJar(jarFilePath);\n\n    // Attempt to load cookies from file if it exists\n    try {\n        await cookieJar.load();\n        console.log(`Loaded cookies from ${jarFilePath}`);\n    } catch (error) {\n        if (error.code === 'ENOENT') {\n            console.log(`No existing cookie jar found at ${jarFilePath}. Starting fresh.`);\n        } else {\n            console.error(`Error loading cookie jar:`, error);\n            return;\n        }\n    }\n\n    // Make a request, cookies will be sent/received via the cookieJar\n    console.log(\"Making initial request to example.com...\");\n    let response = await fetch(cookieJar, \"https://example.com\");\n    console.log(`Status: ${response.status}`);\n    console.log(\"Headers received:\", response.headers.raw());\n\n    // You can now make another request to a different page on the same domain or a subdomain\n    // and the cookies from the first request will be automatically sent.\n    console.log(\"Making second request to example.com/path...\");\n    response = await fetch(cookieJar, \"https://example.com/path\");\n    console.log(`Status: ${response.status}`);\n\n    // Save the received cookies to disk\n    await cookieJar.save();\n    console.log(`Saved cookies to ${jarFilePath}`);\n})();","lang":"javascript","description":"Demonstrates initializing a CookieJar with file persistence, loading existing cookies, making multiple requests with automatic cookie handling, and saving updated cookies to disk.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}