1. License
“Permission is hereby granted, free of charge, to any person obtaining a copy of this software”
MIT allows use in paid and closed products.
github.com/jshttp/cookie/blob/master/LICENSE3. Used by agents' projects
Dependency in 18 public GitHub projects set up for AI coding agents that we scanned (0.3%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error
What cookie does
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.
What people build with it
Keep a user logged in
After sign-in, your server sends a session cookie that page scripts cannot read and that only travels over HTTPS.
Read who is visiting
On each request your server turns the browser's cookie line into a simple list of names and values, like session and theme.
Remember a visitor's choice
Save a name, language or dark mode choice in a cookie and greet the visitor with it on the next visit.
Log a user out Idea
Send the same cookie back empty with a lifetime of zero, so the browser drops the session at once.
Check cookies your server sends
In tests, or in a proxy in front of another service, turn a Set-Cookie line back into its parts and check each setting.
Cookies in a tiny server Idea
A small Node.js server or serverless function without Express can still read and set cookies without a full framework.
cookie popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How cookie is used
- 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%).
By coding agent
Often used with
More about cookie
Funding
- Open Collective: https://opencollective.com/express
Agent Skills for it
- 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
Alternatives
cookie This page
Pick cookie-parser when your server uses Express and you want req.cookies filled on every request, with optional signed cookies.
Pick js-cookie to read and write cookies from page scripts in the browser, not on the server.
Pick set-cookie-parser when you receive responses with several Set-Cookie lines from another service and need them all split out.
Get started
Tell your AI assistant
“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.”
Install the package in your server project (it needs Node.js 22 or newer).
$ npm install cookieImport it as a module.
import * as cookie from "cookie";Read the request's cookies with parseCookie and send new ones with stringifySetCookie.
const cookieObject = cookie.parseCookie("foo=bar; equation=E%3Dmc%5E2"); // { foo: 'bar', equation: 'E=mc^2' }
Mistakes to avoid
2.0.0 removed the old names (our run showed typeof cookie.parse is "undefined") and stringifySetCookie takes only an object.
2.x is ESM only and states that older Node.js versions are not supported.
maxAge here is in seconds, so a millisecond value keeps the cookie 1000 times longer than meant.
Old versions let crafted names change other settings; current versions throw a TypeError (our run - cookie name is invalid).
The library only turns header text into values; anyone can edit the cookie text in their browser.
Questions
Why does cookie.parse not exist anymore?
Version 2.0.0 removed the old names. Use parseCookie to read and stringifySetCookie to write.
Can I still use require("cookie")?
Only on Node.js 22 or newer, which can load modern modules with require. Older Node.js versions are not supported by 2.x.
What happens if a cookie value cannot be decoded?
The default decoder catches the error and returns the original text instead of failing.
Should I set both maxAge and expires?
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.
Can I use it in a commercial product?
Yes. It is MIT licensed.