{
 "kind": "tool",
 "slug": "cookie",
 "path": "tools/cookie/",
 "name": "cookie",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Utilities",
   "tools/utilities/"
  ]
 ],
 "lead": "Read and set browser cookies on your server.",
 "chips": [
  {
   "label": "Utilities",
   "path": "tools/utilities/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install cookie"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/jshttp/cookie"
  },
  {
   "label": "Website",
   "href": "https://github.com/jshttp/cookie#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Permission is hereby granted, free of charge, to any person obtaining a copy of this software",
   "note": "MIT allows use in paid and closed products.",
   "src": "https://github.com/jshttp/cookie/blob/master/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 5, 2026",
   "note": "Latest GitHub release Nov 5, 2026. ",
   "src": "https://github.com/jshttp/cookie"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "18 projects",
   "status": "info",
   "sub": "#83 of 408 in its category",
   "note": "Dependency in 18 public GitHub projects set up for AI coding agents that we scanned (0.3%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Community skills",
   "status": "info",
   "sub": "2 skills by others",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What cookie does",
   "parts": [
    {
     "t": "prose",
     "text": "cookie is a small free JavaScript library for the server side of a website. It reads the cookies a browser sends, such as a login session or a chosen theme, and writes new ones with the right safety settings. Frameworks use it inside; you call it yourself in a plain Node.js server or a small function."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Keep a user logged in",
       "text": "After sign-in, your server sends a session cookie that page scripts cannot read and that only travels over HTTPS.",
       "idea": false
      },
      {
       "title": "Read who is visiting",
       "text": "On each request your server turns the browser's cookie line into a simple list of names and values, like session and theme.",
       "idea": false
      },
      {
       "title": "Remember a visitor's choice",
       "text": "Save a name, language or dark mode choice in a cookie and greet the visitor with it on the next visit.",
       "idea": false
      },
      {
       "title": "Log a user out",
       "text": "Send the same cookie back empty with a lifetime of zero, so the browser drops the session at once.",
       "idea": true
      },
      {
       "title": "Check cookies your server sends",
       "text": "In tests, or in a proxy in front of another service, turn a Set-Cookie line back into its parts and check each setting.",
       "idea": false
      },
      {
       "title": "Cookies in a tiny server",
       "text": "A small Node.js server or serverless function without Express can still read and set cookies without a full framework.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "cookie popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "62",
       "of": "/ 100",
       "l": "Gid Score, #854 overall"
      },
      {
       "n": "347M",
       "l": "downloads a week, npm"
      },
      {
       "n": "1,538",
       "l": "GitHub stars"
      },
      {
       "n": "18",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How cookie is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "cookie is a dependency in 18 of the 6,258 public GitHub projects set up for AI coding agents that we scanned, too few to describe it from them alone. Our scan also samples projects by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750); counting those, it appears in 73 projects, and what it is used with below comes from all of them.",
      "Projects that use it most often also use dotenv (56.2%), Zod (68.5%), React (76.7%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "13 projects, 0.4%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "7 projects, 0.3%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "7 projects, 0.2%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 56.2% of its projects",
       "v": "dotenv",
       "path": "tools/dotenv/"
      },
      {
       "l": "In 68.5% of its projects",
       "v": "Zod",
       "path": "tools/zod/"
      },
      {
       "l": "In 76.7% of its projects",
       "v": "React",
       "path": "tools/react/"
      },
      {
       "l": "In 43.8% of its projects",
       "v": "Framer Motion",
       "path": "tools/framer-motion/"
      },
      {
       "l": "In 42.5% of its projects",
       "v": "TanStack Query",
       "path": "tools/tanstack-react-query/"
      },
      {
       "l": "In 41.1% of its projects",
       "v": "jose",
       "path": "tools/jose/"
      },
      {
       "l": "In 41.1% of its projects",
       "v": "date-fns",
       "path": "tools/date-fns/"
      },
      {
       "l": "In 39.7% of its projects",
       "v": "next-themes",
       "path": "tools/next-themes/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about cookie",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "Open Collective: https://opencollective.com/express"
       ]
      },
      {
       "title": "Agent Skills for it",
       "path": "skills/",
       "items": [
        "cookie-sync: Sync cookies from local Chrome to a Browserbase persistent context so the browse CLI can access authenticated sites. Use when the user wants",
        "cookie-copy: Copies selected-site cookies between local profiles of the same macOS Chrome. Use for cookie copy, 复制 Cookie, 搬登录态 or reusing an existing Ch"
       ]
      },
      {
       "title": "More in Utilities",
       "path": "tools/utilities/",
       "items": [
        {
         "text": "clsx",
         "path": "tools/clsx/"
        },
        {
         "text": "date-fns",
         "path": "tools/date-fns/"
        },
        {
         "text": "PyYAML",
         "path": "tools/pyyaml/"
        },
        {
         "text": "uuid",
         "path": "tools/uuid/"
        },
        {
         "text": "yaml",
         "path": "tools/yaml/"
        },
        {
         "text": "js-yaml",
         "path": "tools/js-yaml/"
        },
        {
         "text": "glob",
         "path": "tools/glob/"
        },
        {
         "text": "Lodash",
         "path": "tools/lodash/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "cookie",
       "me": true,
       "facts": [
        "MIT",
        "Gid 62",
        "347M/wk"
       ]
      },
      {
       "name": "cookie-parser",
       "why": "Pick cookie-parser when your server uses Express and you want req.cookies filled on every request, with optional signed cookies.",
       "path": "tools/cookie-parser/",
       "facts": []
      },
      {
       "name": "js-cookie",
       "why": "Pick js-cookie to read and write cookies from page scripts in the browser, not on the server.",
       "path": "tools/js-cookie/",
       "facts": []
      },
      {
       "name": "set-cookie-parser",
       "why": "Pick set-cookie-parser when you receive responses with several Set-Cookie lines from another service and need them all split out.",
       "path": "tools/set-cookie-parser/",
       "facts": []
      }
     ],
     "more": "Compare cookie with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use the npm package cookie (pin cookie@2.0.2, Node.js 22+, ESM) to read req.headers.cookie with parseCookie and set the session with stringifySetCookie using httpOnly, secure, sameSite lax, path / and maxAge in seconds; never use the old parse/serialize names."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install the package in your server project (it needs Node.js 22 or newer).",
       "code": "$ npm install cookie",
       "src": "https://github.com/jshttp/cookie/blob/master/README.md"
      },
      {
       "text": "Import it as a module.",
       "code": "import * as cookie from \"cookie\";",
       "src": "https://github.com/jshttp/cookie/blob/master/README.md"
      },
      {
       "text": "Read the request's cookies with parseCookie and send new ones with stringifySetCookie.",
       "code": "const cookieObject = cookie.parseCookie(\"foo=bar; equation=E%3Dmc%5E2\");\n// { foo: 'bar', equation: 'E=mc^2' }\n",
       "src": "https://github.com/jshttp/cookie/blob/master/README.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "cookie.parse(header) and cookie.serialize(name, value, options) from 0.x/1.x examples",
       "fix": "cookie.parseCookie(header) and cookie.stringifySetCookie({ name, value, ...options })",
       "why": "2.0.0 removed the old names (our run showed typeof cookie.parse is \"undefined\") and stringifySetCookie takes only an object."
      },
      {
       "dont": "npm install cookie in a project on Node.js 18 or 20",
       "fix": "Run Node.js 22+, or pin cookie@1.1.1 on older Node.js",
       "why": "2.x is ESM only and states that older Node.js versions are not supported."
      },
      {
       "dont": "maxAge: 7 * 24 * 60 * 60 * 1000  // milliseconds, as in Express res.cookie",
       "fix": "maxAge: 60 * 60 * 24 * 7  // seconds",
       "why": "maxAge here is in seconds, so a millisecond value keeps the cookie 1000 times longer than meant."
      },
      {
       "dont": "Building the cookie name, path or domain from user input",
       "fix": "Fix names, paths and domains in your code; put user data only in the value",
       "why": "Old versions let crafted names change other settings; current versions throw a TypeError (our run - cookie name is invalid)."
      },
      {
       "dont": "Storing the user id itself in the cookie and trusting it on the next request",
       "fix": "Store a random session id (or a signed or encrypted value, e.g. with jose or iron-session) and look it up on the server",
       "why": "The library only turns header text into values; anyone can edit the cookie text in their browser."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Why does cookie.parse not exist anymore?",
       "a": "Version 2.0.0 removed the old names. Use parseCookie to read and stringifySetCookie to write.",
       "evidence": {
        "url": "https://github.com/jshttp/cookie/releases/tag/v2.0.0",
        "quote": "The old parse and stringify methods have been renamed: parseCookie and stringifySetCookie"
       }
      },
      {
       "q": "Can I still use require(\"cookie\")?",
       "a": "Only on Node.js 22 or newer, which can load modern modules with require. Older Node.js versions are not supported by 2.x.",
       "evidence": {
        "url": "https://github.com/jshttp/cookie/releases/tag/v2.0.0",
        "quote": "and older node versions are not supported."
       }
      },
      {
       "q": "What happens if a cookie value cannot be decoded?",
       "a": "The default decoder catches the error and returns the original text instead of failing.",
       "evidence": {
        "url": "https://github.com/jshttp/cookie/blob/master/README.md",
        "quote": "If an error is thrown it will return the cookie's original value."
       }
      },
      {
       "q": "Should I set both maxAge and expires?",
       "a": "The README warns that not every client follows the rule that maxAge wins, so if you set both they should point to the same moment.",
       "evidence": {
        "url": "https://github.com/jshttp/cookie/blob/master/README.md",
        "quote": "so if both are set, they should point to the same date and time."
       }
      },
      {
       "q": "Can I use it in a commercial product?",
       "a": "Yes. It is MIT licensed.",
       "evidence": {
        "url": "https://github.com/jshttp/cookie/blob/master/LICENSE",
        "quote": "Permission is hereby granted, free of charge, to any person obtaining a copy of this software"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm cookie"
  ],
  [
   "Category",
   "Utilities"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Gid Score",
   "62.2"
  ],
  [
   "Rank in category",
   "#83 of 408"
  ],
  [
   "GitHub",
   "jshttp/cookie"
  ],
  [
   "Last change",
   "Nov 5, 2026"
  ]
 ],
 "good": [
  "Version 2 needs Node.js 22 or newer and loads only as a modern module; older Node.js versions are not supported.",
  "Version 2 renamed the old functions; code and examples written for 1.x or 0.x need the new names.",
  "A cookie without an expiry date or a lifetime is dropped when the browser session ends."
 ],
 "checked_line": "Read by AgentGid from 9 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/jshttp.png"
}