Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

cookie

Read and set browser cookies on your server.

UtilitiesNPM

GitHubWebsite

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/LICENSE

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

62 / 100
Gid Score, #854 overall
347M
downloads a week, npm
1,538
GitHub stars
18
agent projects use it
cookie: downloads per weeknpm, cookie 347,234,031
cookie: GitHub starsjshttp/cookie 1,538

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

13 projects, 0.4%
7 projects, 0.3%
7 projects, 0.2%

Often used with

In 56.2% of its projects
In 68.5% of its projects
In 76.7% of its projects
In 43.8% of its projects
In 42.5% of its projects
In 41.1% of its projects
In 41.1% of its projects
In 39.7% of its projects

More about cookie

Funding
  • Open Collective: https://opencollective.com/express

See all

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

See all

More in Utilities

Alternatives

cookie This page

MITGid 62347M/wk

cookie-parser

Pick cookie-parser when your server uses Express and you want req.cookies filled on every request, with optional signed cookies.

js-cookie

Pick js-cookie to read and write cookies from page scripts in the browser, not on the server.

set-cookie-parser

Pick set-cookie-parser when you receive responses with several Set-Cookie lines from another service and need them all split out.

Compare cookie with another tool

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.”

  1. Install the package in your server project (it needs Node.js 22 or newer).

    $ npm install cookie

    From github.com/jshttp/cookie/blob/master/README.md

  2. Import it as a module.

    import * as cookie from "cookie";

    From github.com/jshttp/cookie/blob/master/README.md

  3. 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' }
    

    From github.com/jshttp/cookie/blob/master/README.md

Mistakes to avoid

cookie.parse(header) and cookie.serialize(name, value, options) from 0.x/1.x examples
cookie.parseCookie(header) and cookie.stringifySetCookie({ name, value, ...options })

2.0.0 removed the old names (our run showed typeof cookie.parse is "undefined") and stringifySetCookie takes only an object.

npm install cookie in a project on Node.js 18 or 20
Run Node.js 22+, or pin cookie@1.1.1 on older Node.js

2.x is ESM only and states that older Node.js versions are not supported.

maxAge: 7 * 24 * 60 * 60 * 1000 // milliseconds, as in Express res.cookie
maxAge: 60 * 60 * 24 * 7 // seconds

maxAge here is in seconds, so a millisecond value keeps the cookie 1000 times longer than meant.

Building the cookie name, path or domain from user input
Fix names, paths and domains in your code; put user data only in the value

Old versions let crafted names change other settings; current versions throw a TypeError (our run - cookie name is invalid).

Storing the user id itself in the cookie and trusting it on the next request
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

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.