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,195 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 →
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
76%
AGPL 3.0

Abby

Developer Tools · Product Management

166

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

View details
31
Repo Health
70
Technical
64
Dependency
Built with
TypeScript 76%
MDX 18%
Updated 1 years ago
TypeScript
95%
MIT

Actual

Invoicing Finance

29,186

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
73
Dependency
Built with
TypeScript 95%
Updated 4 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
JavaScript
95%
MIT

AnythingLLM

AI Assistants · Automation · Developer Tools

66,533

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

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript 95%
Updated 6 days ago
JavaScript
100%
Other

Automatisch

Automation · No Code Platforms

13,979

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
62
Dependency
Built with
JavaScript 100%
Updated 7 months 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
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
JavaScript
90%
Other

CodeSandbox

Code Editors · Developer Tools

13,650

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

View details
67
Repo Health
76
Technical
62
Dependency
Built with
JavaScript 90%
Updated 3 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