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

JavaScript
94%
AGPL 3.0

MyApi

AI Agents

23

A privacy-first personal API gateway for AI agents — connect your services once, issue scoped tokens to agents like OpenClaw, Hermes, or Claude Code, and keep a full audit trail instead of scattering raw credentials across .env files.

View details
37
Repo Health
64
Technical
73
Dependency
Built with
JavaScript 94%
Updated 3 weeks ago
TypeScript
97%
Other

nango

Authentication · Automation · Developer Tools

12,963

Build product integrations with AI using 800+ APIs — auth, proxy, and TypeScript functions on production-grade infrastructure.

View details
94
Repo Health
85
Technical
67
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,340

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
91
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 6 days ago
TypeScript
85%
GPL 3.0

Notesnook

File Storage · Note Taking · Security

14,822

End-to-end encrypted, open-source note-taking where your data stays yours — even from the server.

View details
91
Repo Health
84
Technical
60
Dependency
Built with
TypeScript 85%
JavaScript 12%
Updated 6 days ago
TypeScript
26%
AGPL 3.0

Omnivore

Bookmarks Archiving · Knowledge Management · Note Taking

16,356

Self-hosted read-it-later platform with highlights, newsletters, PDFs, and seamless Obsidian and Logseq integration.

View details
90
Repo Health
74
Technical
65
Dependency
Built with
TypeScript 26%
JavaScript 24%
HTML 20%
Updated 1 weeks ago
TypeScript
96%
Apache 2.0

OneUptime

Monitoring

7,751

The complete open-source observability platform that replaces PagerDuty, Datadog, Sentry, and StatusPage with a single self-hostable system.

View details
91
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 96%
Updated 6 days ago
TypeScript
95%
MIT

Open Lovable

AI Development

28,793

An open-source AI app builder that scrapes a live website and recreates it as a modern React app through chat — built by Firecrawl as a self-hostable example of the Lovable.dev workflow.

View details
50
Repo Health
66
Technical
69
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
JavaScript
90%
Other

OpenSign

Digital Signiture

7,163

Self-host a full-featured DocuSign alternative with unlimited e-signatures, multi-signer workflows, and cryptographic PDF signing.

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

Pangolin

Networking

23,187

An open-source, identity-based zero-trust remote access platform built on WireGuard — a self-hostable alternative to Cloudflare Tunnel and Twingate with SSO, OIDC, and tunneled reverse proxying.

View details
87
Repo Health
68
Technical
68
Dependency
Built with
TypeScript 99%
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