cookie

Basic HTTP cookie parser and serializer for HTTP servers, with zero dependencies and full RFC 6265 support.

Library
npm
v2.0.1
1,537 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 12
Maintenance 20
Community 72
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 88
Code Quality 90
Innovation 88
Learning Curve 90

cookie is a small, focused Node.js library for parsing and serializing HTTP cookies. It reads incoming Cookie headers into plain name-value objects and turns cookie objects back into header strings, and it does the same for Set-Cookie headers including all standard attributes (Domain, Path, Max-Age, Expires, HttpOnly, Secure, SameSite, Priority, and Partitioned).

Built with zero runtime dependencies and shipped as a sub-1.4KB module, it follows RFC 6265 closely while giving you full control over value encoding and decoding. It is the parsing layer beneath much of the Node ecosystem, used by frameworks like Express and countless session and authentication middlewares.

What You Get

  • parseCookie and stringifyCookie for converting between Cookie header strings and plain name-value objects
  • parseSetCookie and stringifySetCookie for reading and writing Set-Cookie headers with all standard attributes
  • Pluggable encode/decode options so you control exactly how cookie values are transformed
  • A zero-dependency, sub-1.4KB, tree-shakeable ESM module with TypeScript types included

Common Use Cases

  • Reading cookies from an incoming request in a raw Node.js HTTP server or a framework
  • Setting session, authentication, or preference cookies with attributes like HttpOnly, Secure, and SameSite
  • Building session or auth middleware that needs precise, spec-compliant cookie handling
  • Serializing and deserializing cookie state without pulling in a heavier framework dependency

Under The Hood

Architecture

The entire library lives in a single module (src/index.ts, ~17KB) exporting four functions: parseCookie, stringifyCookie, parseSetCookie, and stringifySetCookie. Parsing is done with a tight character-index scanning loop over the header string rather than expensive String.split/regex-splitting, locating = and ; delimiters manually for speed. Validation of names, values, domains, and paths uses a set of precompiled RFC 6265 regular expressions defined at module top. Parsed results are collected into a null-prototype NullObject container so attacker-controlled cookie names can never pollute Object.prototype.

Tech Stack

Written in TypeScript with zero runtime dependencies and distributed as a native ESM module ("type": "module", exports: "./dist/index.js", sideEffects: false). It targets Node.js >= 22, is built and tested via @borderless/ts-scripts on top of Vitest, and enforces a strict bundle budget of 1.4KB with size-limit. Bundled .d.ts types ship for TypeScript consumers.

Code Quality

Code quality is high: each of the four functions has a dedicated spec file (parse-cookie.spec.ts, parse-set-cookie.spec.ts, stringify-cookie.spec.ts, stringify-set-cookie.spec.ts) plus snapshot fixtures and benchmark suites that parse real top-site cookie headers. The source is densely commented with inline RFC 6265 grammar references explaining each regular expression, and the public surface is fully and strictly typed.

API Design

The public API is deliberately minimal and symmetric — a parse and a stringify function for each of the Cookie and Set-Cookie header types — which makes it easy to learn and hard to misuse. Both parse functions accept a decode option and both stringify functions accept an encode option, with safe URL-encoding defaults wrapped in try..catch, so custom value transforms are a one-line override. Getting started requires no configuration or setup beyond a single import.

Used by 31 apps in this directory

TypeScript
91%
Other

FastGPT

AI Agents · AI Development

29,900

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
66
Dependency
Built with
TypeScript 91%
Updated 6 days ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,991

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
63
Dependency
Built with
TypeScript 83%
Python 11%
Updated 1 weeks ago
TypeScript
68%
MIT

Hoppscotch

Developer Tools

80,676

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
62
Dependency
Built with
TypeScript 68%
Vue 24%
Updated 1 weeks ago
TypeScript
66%
MIT

Jitsu

Data Engineering

5,110

Open-source, fully-scriptable data ingestion engine that streams events from web, apps, and APIs to any data warehouse in real time.

View details
89
Repo Health
79
Technical
66
Dependency
Built with
TypeScript 66%
Go 32%
Updated 1 weeks ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,980

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 6 days ago
TypeScript
98%
Other

LobeHub

AI Assistants · Automation · Productivity

83,455

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
92%
Apache 2.0

Apache Maka

AI Agents · AI Development · Developer Tools

5,868

An Apache-incubated agent workspace that treats every model call, tool run, and permission decision as an append-only, replayable event log instead of disposable chat history.

View details
82
Repo Health
85
Technical
73
Dependency
Built with
TypeScript 92%
Updated 6 days ago
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript 95%
Updated 1 years ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers