cors

Node.js CORS middleware for Express and Connect that sets standards-compliant headers to control cross-origin browser access.

Library
npm
v2.8.6
6,189stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
52/100Fair
Development Activity20
Maintenance20
Community68
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture65
Code Quality75
Innovation80
Learning Curve85

cors is a lightweight Node.js middleware for Express and Connect applications that adds Cross-Origin Resource Sharing (CORS) response headers to HTTP requests. Rather than blocking anything itself, it configures the Access-Control-* headers browsers use to decide whether client-side JavaScript from another origin may read a response, letting you enable open access, lock requests to specific origins, or compute permissions dynamically per request.

With tens of millions of weekly downloads, it has become the de facto standard for handling CORS in the Express ecosystem, valued for its tiny single-file implementation, sane defaults, and flexible configuration options covering static origins, regular expressions, arrays, and asynchronous origin callbacks.

What You Get

  • A single cors() Express/Connect middleware function you can mount globally or per-route
  • Support for static origins, regex patterns, arrays of origins, and async origin-validation callbacks
  • Built-in handling of CORS preflight (OPTIONS) requests, including a configurable success status code for legacy browsers
  • Fine-grained control over allowed/exposed headers, credentials, and max-age caching of preflight results

Common Use Cases

  • Enabling a public REST API to be called from browser JavaScript hosted on a different domain
  • Restricting cross-origin access to a fixed whitelist of trusted frontend origins
  • Dynamically validating request origins against a database-backed allowlist per request
  • Supporting credentialed (cookie-based) cross-origin requests between a SPA and its API server

Under The Hood

Architecture: cors ships as a single-file library (lib/index.js, ~230 lines) wrapped in an IIFE and exposed via module.exports. The public export, middlewareWrapper, normalizes whatever was passed in—a static options object or a (req, cb) delegate function—into a uniform async callback shape, then returns the actual corsMiddleware(req, res, next) Express handler. On each request, that handler resolves the effective options, resolves the effective origin (which may itself be computed asynchronously via a user-supplied function), and calls an internal cors() function that branches on whether the request is a CORS preflight (OPTIONS) or an actual request. Each branch assembles a nested array of header descriptor objects from small single-purpose configureOrigin/configureMethods/configureCredentials/configureAllowedHeaders/configureExposedHeaders/configureMaxAge functions, which applyHeaders then flattens recursively and writes onto the response (routing Vary headers through the separate vary package to merge correctly with any headers already present).

Tech Stack: The library targets plain Node.js with no build step and deliberately old-school ES5 syntax (var, IIFE, no arrow functions or classes) to keep compatibility back to engines.node >= 0.10. It has exactly two runtime dependencies: object-assign (an Object.assign polyfill, mirroring Express’s own low-dependency philosophy) and vary (for correctly appending to the Vary header). Development tooling is equally minimal: eslint for linting, mocha + supertest for running assertions against real Express apps, and nyc for coverage reporting.

Code Quality: Test coverage is substantial relative to the implementation size—test/test.js alone runs to 731 lines, supplemented by test/example-app.js, test/error-response.js, and a regression test for a specific historical GitHub issue (test/issue-2.js), all exercised against live supertest-driven Express servers rather than mocked requests. Function names (configureOrigin, isOriginAllowed, applyHeaders) are consistently descriptive, and the callback-first error propagation follows standard Node.js conventions throughout. The codebase carries no TypeScript and no bundled type declarations (types are maintained separately via @types/cors on DefinitelyTyped), and there is no JSDoc on internal functions, which is the main gap for a library of its ubiquity.

API Design: The module exports a single default function that can be called with no arguments for permissive defaults, a static options object, or an async options/origin delegate for advanced per-request logic—covering the simple case and the complex case with one consistent call shape. Option names (origin, methods, allowedHeaders, credentials, maxAge) map directly onto the CORS specification’s own vocabulary, so developers already familiar with the browser CORS model incur almost no additional learning overhead, and the middleware can be mounted globally or scoped to a single route without any API changes.

Used by 77 apps in this directory

TypeScript
76%
AGPL 3.0

Abby

Developer Tools · Product Management

167

Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.

View details
30
Repo Health
70
Technical
63
Dependency
Built with
TypeScript76%
MDX18%
Updated 1 years ago
TypeScript
94%
MIT

Actual

Invoicing Finance

28,224

Local-first personal finance with envelope budgeting, end-to-end encryption, and multi-device sync — no subscription required.

View details
93
Repo Health
85
Technical
77
Dependency
Built with
TypeScript94%
Updated yesterday
TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

32,102

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
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript95%
Updated today
JavaScript
95%
MIT

AnythingLLM

Developer Tools · Automation · AI Assistants

64,914

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
91
Repo Health
78
Technical
68
Dependency
Built with
JavaScript95%
Updated today
JavaScript
100%
Other

Automatisch

Automation · No Code Platforms

13,936

Self-hosted, no-code workflow automation that keeps your data on your own servers—a privacy-first alternative to Zapier with 90+ integrations.

View details
49
Repo Health
78
Technical
64
Dependency
Built with
JavaScript100%
Updated 6 months ago
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

10,880

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
83
Repo Health
69
Technical
65
Dependency
Built with
TypeScript92%
Updated 2 weeks ago
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,041

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
65
Dependency
Built with
JavaScript99%
Updated 6 days ago
TypeScript
97%
AGPL 3.0

Checkmate

Devops · Analytics · Monitoring

10,556

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

View details
91
Repo Health
82
Technical
69
Dependency
Built with
TypeScript97%
Updated yesterday
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,633

Instantly ready browser-based IDE that runs full npm dependency resolution and transpilation entirely client-side, with no server needed.

View details
65
Repo Health
76
Technical
63
Dependency
Built with
JavaScript90%
Updated 1 months 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

Search