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,194 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
49 /100 Fair
Development Activity 8
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 →
69 /100 Good
Architecture 65
Code Quality 75
Innovation 80
Learning Curve 85

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 79 apps in this directory

TypeScript
84%
Apache 2.0

Continue

AI Code Assistants · AI Development · Automation

36,303

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
66
Repo Health
88
Technical
62
Dependency
Built with
TypeScript 84%
Updated 1 weeks ago
Go
75%
MIT

Digger

Automation · Developer Tools · Devops

5,057

Run Terraform and OpenTofu natively inside your existing CI pipeline — no separate runners, no third-party secrets, no extra compute costs.

View details
78
Repo Health
73
Technical
66
Dependency
Built with
Go 75%
TypeScript 15%
Updated 1 weeks ago
TypeScript
80%
Other

Directus

CMS · Low Code Platforms

38,629

Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.

View details
93
Repo Health
82
Technical
76
Dependency
Built with
TypeScript 80%
Vue 19%
Updated 1 weeks ago
Python
47%
MIT

Docs

CMS · File Storage

16,942

Open-source collaborative knowledge platform with real-time editing, AI writing tools, and full self-hosting control — built by the French and German governments.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Python 47%
TypeScript 46%
Updated 1 weeks ago
TypeScript
96%
Other

Dyad

AI Assistants · AI Code Assistants · AI Development

22,046

Build AI-powered apps locally with your own keys, your own models, and zero cloud lock-in.

View details
87
Repo Health
83
Technical
69
Dependency
Built with
TypeScript 96%
Updated 1 weeks ago
Go
47%
Apache 2.0

e2a

AI Agents · Automation

194

Give your AI agents a real, authenticated email address — with SPF/DKIM-verified inbound, HMAC-signed delivery, WebSocket fan-out, and human-in-the-loop approval built in.

View details
79
Repo Health
80
Technical
71
Dependency
Built with
Go 47%
TypeScript 27%
Python 13%
Updated 1 weeks ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
TypeScript
72%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

194,745

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 72%
Python 12%
Updated 6 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,521

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
75
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 2 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