{
 "kind": "tool",
 "slug": "cors",
 "path": "tools/cors/",
 "name": "cors",
 "maker": null,
 "density": "profile",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "HTTP servers and APIs",
   "tools/http-servers/"
  ]
 ],
 "lead": "Express/Node.js middleware for handling Cross-Origin Resource Sharing.",
 "chips": [
  {
   "label": "HTTP servers and APIs",
   "path": "tools/http-servers/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install cors"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/expressjs/cors"
  },
  {
   "label": "Website",
   "href": "https://github.com/expressjs/cors#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": null,
   "note": "License from npm.",
   "src": "https://github.com/expressjs/cors"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Jun 2, 2026",
   "note": "Latest GitHub release Jan 22, 2026. ",
   "src": "https://github.com/expressjs/cors"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "196 projects",
   "status": "info",
   "sub": "#4 of 102 in its category",
   "note": "Dependency in 196 public GitHub projects set up for AI coding agents that we scanned (3.1%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What cors does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "cors popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "77",
       "of": "/ 100",
       "l": "Gid Score, #163 overall"
      },
      {
       "n": "131M",
       "l": "downloads a week, npm"
      },
      {
       "n": "6,198",
       "l": "GitHub stars"
      },
      {
       "n": "196",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How cors is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "100 projects, 4.1%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "94 projects, 2.9%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "91 projects, 3.0%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "30 projects, 10.8%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "16 projects, 3.4%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "11 projects, 3.2%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      },
      {
       "l": "9 projects, 1.9%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "8 projects, 5.7%",
       "v": "Kiro",
       "path": "agents/kiro/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 98.0% of its projects",
       "v": "Express",
       "path": "tools/express/"
      },
      {
       "l": "In 73.5% of its projects",
       "v": "dotenv",
       "path": "tools/dotenv/"
      },
      {
       "l": "In 40.8% of its projects",
       "v": "jsonwebtoken",
       "path": "tools/jsonwebtoken/"
      },
      {
       "l": "In 37.2% of its projects",
       "v": "Helmet",
       "path": "tools/helmet/"
      },
      {
       "l": "In 31.1% of its projects",
       "v": "uuid",
       "path": "tools/uuid/"
      },
      {
       "l": "In 56.1% of its projects",
       "v": "Zod",
       "path": "tools/zod/"
      },
      {
       "l": "In 30.1% of its projects",
       "v": "concurrently",
       "path": "tools/concurrently/"
      },
      {
       "l": "In 29.1% of its projects",
       "v": "express-rate-limit",
       "path": "tools/express-rate-limit/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "cors in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Exact origins and patterns in one list",
       "v": "<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."
      },
      {
       "l": "Allowlist loaded from a database",
       "v": "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."
      },
      {
       "l": "A different policy for each request",
       "v": "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>."
      },
      {
       "l": "App-level mount answers preflight",
       "v": "With <code>app.use(cors())</code>, OPTIONS preflight requests are handled for every route without extra handlers."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Defaults allow every origin",
       "v": "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."
      },
      {
       "l": "Not access control",
       "v": "The README warns that curl, Postman and other servers ignore CORS. It points to authentication and authorization for protecting an API."
      },
      {
       "l": "Per-route use needs preflight handlers",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Allow a single origin on one route"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Javascript",
       "code": "var express = require('express')\nvar cors = require('cors')\nvar app = express()\n\nvar corsOptions = {\n  origin: 'http://example.com',\n  optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204\n}\n\n// Adds headers: Access-Control-Allow-Origin: http://example.com, Vary: Origin\napp.get('/products/:id', cors(corsOptions), function (req, res, next) {\n  res.json({msg: 'Hello'})\n})\n\napp.listen(80, function () {\n  console.log('web server listening on port 80')\n})"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about cors",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "Open Collective: https://opencollective.com/express"
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "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"
       ]
      },
      {
       "title": "More in HTTP servers and APIs",
       "path": "tools/http-servers/",
       "items": [
        {
         "text": "Uvicorn",
         "path": "tools/uvicorn/"
        },
        {
         "text": "FastAPI",
         "path": "tools/fastapi/"
        },
        {
         "text": "Express",
         "path": "tools/express/"
        },
        {
         "text": "python-multipart",
         "path": "tools/python-multipart/"
        },
        {
         "text": "Hono",
         "path": "tools/hono/"
        },
        {
         "text": "Flask",
         "path": "tools/flask/"
        },
        {
         "text": "Starlette",
         "path": "tools/starlette/"
        },
        {
         "text": "express-rate-limit",
         "path": "tools/express-rate-limit/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "cors",
       "me": true,
       "facts": [
        "MIT",
        "Gid 77",
        "131M/wk"
       ]
      },
      {
       "name": "NestJS",
       "why": "Progressive Node.js framework for building scalable and maintainable server-side applications.",
       "path": "tools/nestjs/",
       "facts": [
        "MIT",
        "Gid 78",
        "26M/wk"
       ]
      }
     ],
     "more": "Compare cors with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "install",
     "intro": "Install it.",
     "code": "npm install cors"
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## cors\n- Do not use cors to protect an API. The server still processes every request, so add authentication and authorization separately.\n- Bare `cors()` sends `Access-Control-Allow-Origin: *`. When that is not intended, set `origin` to a string, RegExp, array or function.\n- For credential-sensitive routes, follow the README's example: it sets `credentials: true` together with one specific `origin`.\n- 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.\n- In an `origin` function, call `callback(error, origin)`. The `origin` value must be a non-function value that the `origin` option accepts.\n- 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.\n- Set `optionsSuccessStatus: 200` if legacy browsers such as IE11 or SmartTVs must work.\n"
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm cors"
  ],
  [
   "Category",
   "HTTP servers and APIs"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "v2.8.6, January 22, 2026"
  ],
  [
   "On GitHub since",
   "January 2013"
  ],
  [
   "Gid Score",
   "76.8"
  ],
  [
   "Rank in category",
   "#4 of 102"
  ],
  [
   "GitHub",
   "expressjs/cors"
  ],
  [
   "Last change",
   "Jun 2, 2026"
  ]
 ],
 "good": [],
 "checked_line": "From the package registry, GitHub and our scan of public agent projects; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/expressjs.png"
}