cookie-parser

Express middleware that parses HTTP Cookie headers into req.cookies, with support for signed and JSON-encoded cookie values.

Library
npm
v1.4.7
2,030 stars
MIT License

Repository Health

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

Technical Analysis

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

cookie-parser is a small, widely-used Express middleware that reads the incoming request’s Cookie header and populates req.cookies with a plain object of cookie name/value pairs, so route handlers never have to parse raw cookie strings themselves. It builds on the standalone cookie package for header parsing and the cookie-signature package for HMAC-based signature verification, exposing a single middleware factory plus a handful of standalone helper functions.

Beyond basic parsing, it understands two conventions Express apps commonly rely on: signed cookies (prefixed s:, verified against one or more secrets and surfaced separately on req.signedCookies) and JSON cookies (prefixed j:, automatically JSON.parse’d). Because it has almost no configuration surface and a single runtime job, it has become a near-default dependency in Express-based session and auth middleware stacks despite receiving only maintenance-level updates.

What You Get

  • A single middleware factory (cookieParser(secret, options)) that populates req.cookies on every request
  • Optional signed-cookie support: verify and unsign s:-prefixed cookie values against one or more secrets, exposed via req.signedCookies
  • Automatic JSON cookie decoding for j:-prefixed values via JSONCookie/JSONCookies
  • Standalone helper exports (signedCookie, signedCookies, JSONCookie, JSONCookies) usable outside the middleware for custom cookie handling
  • Pass-through options support to the underlying cookie package’s parser (e.g. custom decode function)

Common Use Cases

  • Reading plain, unsigned cookies (feature flags, UI preferences, tracking IDs) in an Express route handler
  • Verifying signed session or auth cookies set by express-session or custom auth middleware without trusting client-tampered values
  • Storing small structured data in a cookie as JSON and having it auto-decoded into an object on every request
  • Building custom cookie-parsing logic in non-Express contexts by importing the exported signedCookie/JSONCookie helpers directly

Under The Hood

Architecture — The entire package is a single ~150-line index.js file that exports one default middleware factory plus four static helper functions (JSONCookie, JSONCookies, signedCookie, signedCookies). The factory closes over a normalized array of secrets and returns a request handler that reads req.headers.cookie, delegates raw parsing to the cookie package, then optionally splits the result into req.cookies and req.signedCookies by running each value through signedCookie (which itself delegates verification to cookie-signature). There is no internal state beyond what is attached per-request, and no async logic — parsing is synchronous end to end.

Tech Stack — Plain ES5-style JavaScript ('use strict', var declarations) with only two runtime dependencies: cookie (RFC 6265 header parsing) and cookie-signature (HMAC signing/verification). No build step or bundler — the package ships index.js directly per its files field. Dev tooling is eslint (standard config) for linting and mocha/supertest/nyc for testing and coverage.

Code Quality — test/cookieParser.js runs 302 lines of mocha+supertest tests covering unsigned, signed, JSON, and malformed-cookie scenarios, including tampered signature handling. The implementation uses Object.create(null) for cookie stores to avoid prototype-pollution surprises and defensive typeof/Array.isArray checks on inputs. Error handling is minimal by design — most edge cases resolve to undefined/false rather than throwing, appropriate given the package’s narrow scope, but there is no input-size or malformed-header hardening beyond what cookie provides.

API Design — The primary API is a single call, app.use(cookieParser()), with zero required configuration; secrets and parsing options are optional positional arguments. Helper functions are exposed as static properties on the default export for advanced use outside the middleware chain. The tradeoff for this simplicity is implicit request mutation (adding cookies/secret/signedCookies onto req), which is idiomatic for Express middleware but relies on convention rather than explicit typing.

Used by 52 apps in this directory

TypeScript
82%
Other

AFFiNE

Collaboration · Note Taking · Productivity

73,040

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 82%
Rust 11%
Updated 6 days ago
TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

33,179

Free, open-source Cowork desktop app that unifies Claude Code, Codex, Gemini CLI, and 20+ AI agents into a single platform with multi-agent teams, 24/7 cron automation, and zero-config built-in agent.

View details
85
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
TypeScript
49%
MPL 2.0

Artillery

Developer Tools · Devops

9,083

Cloud-scale load testing and functional testing for APIs, WebSockets, gRPC, and headless browsers, distributed across AWS Lambda or Fargate with zero infrastructure to manage.

View details
89
Repo Health
73
Technical
68
Dependency
Built with
TypeScript 49%
JavaScript 48%
Updated 1 weeks ago
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

11,049

A self-hosted, AI-powered card note-taking tool that lets you capture fleeting thoughts instantly and retrieve them with natural language search.

View details
75
Repo Health
69
Technical
63
Dependency
Built with
TypeScript 92%
Updated 1 months ago
TypeScript
70%
Other

Budibase

Low Code Platforms · No Code Platforms

28,324

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
91
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 70%
Svelte 26%
Updated 1 weeks ago
TypeScript
96%
Other

Cal.diy

Scheduling

48,697

The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.

View details
91
Repo Health
86
Technical
65
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
TypeScript
96%
Other

CapRover

Developer Tools · Devops · Hosting Control Panel

15,173

Deploy any app, database, or website to your own server in minutes—no Docker or Linux expertise required.

View details
87
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,063

Open-source reporting platform to build live dashboards from SQL, NoSQL, APIs, and SaaS tools with an AI assistant that creates charts from natural language.

View details
90
Repo Health
83
Technical
64
Dependency
Built with
JavaScript 99%
Updated 1 weeks ago
TypeScript
98%
AGPL 3.0

Checkmate

Analytics · Devops · Monitoring

10,895

Self-hosted uptime and infrastructure monitoring with multi-protocol checks, global geo-coverage, and beautiful real-time dashboards.

View details
90
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 98%
Updated 1 weeks 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