Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

cors

Express/Node.js middleware for handling Cross-Origin Resource Sharing.

HTTP servers and APIsNPM

GitHubWebsite

1. License

License from npm.

github.com/expressjs/cors

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What cors does

cors is a small Express/Connect middleware that only sets CORS response headers, and its README states plainly that this neither blocks requests nor protects an API.

cors popularity

77 / 100
Gid Score, #163 overall
131M
downloads a week, npm
6,198
GitHub stars
196
agent projects use it
cors: downloads per weeknpm, cors 130,553,200
cors: GitHub starsexpressjs/cors 6,198

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How cors is used

  • cors is a dependency in 196 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (4.0% of the 4,867 JavaScript/TypeScript ones), #4 of 102 in http servers and apis.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 816; those are left out of every share on this page.
  • The most used alternative in our scan is NestJS (35 projects).
  • Projects that use it most often also use Express (98.0%), dotenv (73.5%), jsonwebtoken (40.8%).
  • It is more common in projects set up for Devin Desktop (10.8%) than for OpenAI Codex (1.9%).

By coding agent

100 projects, 4.1%
94 projects, 2.9%
91 projects, 3.0%
30 projects, 10.8%
16 projects, 3.4%
11 projects, 3.2%
9 projects, 1.9%
8 projects, 5.7%

Often used with

In 98.0% of its projects
In 73.5% of its projects
In 40.8% of its projects
In 37.2% of its projects
In 31.1% of its projects
In 56.1% of its projects
In 30.1% of its projects
In 29.1% of its projects

cors in practice

Strengths

Exact origins and patterns in one list

<code>origin</code> can be an array that mixes strings and regular expressions. The README's example accepts one exact origin plus any subdomain of a second domain.

Allowlist loaded from a database

The function form of <code>origin</code> receives the request origin and a <code>callback(error, origin)</code>. The README says this form is meant for loading allowed origins from storage.

A different policy for each request

You can pass a function of <code>(req, callback)</code> instead of static options. The README's example gives <code>/auth/connect/</code> routes one origin with <code>credentials: true</code> and opens every other route with <code>*</code>.

App-level mount answers preflight

With <code>app.use(cors())</code>, OPTIONS preflight requests are handled for every route without extra handlers.

Watch out for

Defaults allow every origin

With no options, the middleware uses origin <code>*</code> and allows GET, HEAD, PUT, PATCH, POST and DELETE. To narrow this, set <code>origin</code> yourself.

Not access control

The README warns that curl, Postman and other servers ignore CORS. It points to authentication and authorization for protecting an API.

Per-route use needs preflight handlers

If you attach <code>cors()</code> to single routes, "complex" requests need an OPTIONS handler. Examples are DELETE and requests with custom headers. You can add the handler per route with <code>app.options('/path', cors())</code>, or across the board with <code>app.options('*', cors())</code> placed before other routes.

Allow a single origin on one route

var express = require('express')
var cors = require('cors')
var app = express()

var corsOptions = {
  origin: 'http://example.com',
  optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}

// Adds headers: Access-Control-Allow-Origin: http://example.com, Vary: Origin
app.get('/products/:id', cors(corsOptions), function (req, res, next) {
  res.json({msg: 'Hello'})
})

app.listen(80, function () {
  console.log('web server listening on port 80')
})

More about cors

Funding
  • Open Collective: https://opencollective.com/express

See all

Packages around it
  • express: web framework it plugs into
  • dotenv: env var loading
  • jsonwebtoken: JWT sign and verify
  • tsx: run TypeScript directly
  • helmet: security headers
  • nodemon: auto-restart in dev
More in HTTP servers and APIs

Alternatives

cors This page

MITGid 77131M/wk

NestJS

Progressive Node.js framework for building scalable and maintainable server-side applications.

MITGid 7826M/wk

Compare cors with another tool

Get started

Install it.

npm install cors

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## cors
- Do not use cors to protect an API. The server still processes every request, so add authentication and authorization separately.
- Bare `cors()` sends `Access-Control-Allow-Origin: *`. When that is not intended, set `origin` to a string, RegExp, array or function.
- For credential-sensitive routes, follow the README's example: it sets `credentials: true` together with one specific `origin`.
- If you attach `cors()` per route instead of `app.use(cors())`, add `app.options('/path', cors())` for routes that use DELETE or custom headers. Alternatively, put `app.options('*', cors())` before other routes.
- In an `origin` function, call `callback(error, origin)`. The `origin` value must be a non-function value that the `origin` option accepts.
- Set `allowedHeaders` and `exposedHeaders` when you need control over them. If they are unset, request headers are reflected and no custom response headers are exposed.
- Set `optionsSuccessStatus: 200` if legacy browsers such as IE11 or SmartTVs must work.