Registry / web-framework / express-cors

express-cors

JSON →
library0.0.3jsnpmunverified

A lightweight middleware for Express.js (versions 0.x to 3.x) that enables Cross-Origin Resource Sharing (CORS) by adding appropriate HTTP headers. Version 0.0.3 is the latest and final release; the package has been abandoned in favor of the more popular 'cors' package. It allows configuration of allowed origins with flexible patterns (including scheme, subdomain, and port wildcards), as well as custom methods, headers, and max age. No longer maintained and incompatible with Express 4+ due to internal API changes and missing CORS preflight handling for non-simple requests.

npm install express-cors
INSTALL
IMPORT
SIG · EXPRESS-CORS
E
express-cors
web-frameworkjavascriptv0.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const cors = require('express-cors')
import cors from 'express-cors'
This package is CommonJS-only and does not support ES modules.
cors function
require('express-cors')
require('express-cors').default
Module exports the middleware function directly; there is no default export.
default
const cors = require('express-cors')
const { cors } = require('express-cors')
No named exports; only the function itself is exported.

Set up Express middleware to allow CORS from example.com and subdomains, with custom methods and headers.

const express = require('express'); const cors = require('express-cors'); const app = express(); app.use(cors({ allowedOrigins: ['example.com', '*.example.com'], methods: ['GET', 'POST'], headers: ['Content-Type', 'Authorization'], maxAge: 3600 })); app.get('/', (req, res) => { res.send('Hello World!'); }); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
deprecatedexpress-cors is deprecated and no longer maintained. Use the cors package instead.
fix
Replace with 'cors' package: npm uninstall express-cors && npm install cors
affects: >=0.0.0
breakingexpress-cors does not support Express 4+; it relies on deprecated Express 3.x internal APIs (e.g., res.setHeader instead of res.set) and may cause errors.
fix
Migrate to cors package which supports Express 4+.
affects: >=0.0.0
gotchaexpress-cors does not handle non-simple CORS requests (preflight) automatically; the OPTIONS method must be explicitly handled.
fix
Add a separate OPTIONS route or use cors package which handles preflight automatically.
affects: >=0.0.0
gotchaThe allowedOrigins option does not support a boolean 'true' to allow any origin; each origin must be explicitly listed.
fix
Use '*' as an origin string if needed, but note that this package's pattern matching may behave unexpectedly.
affects: >=0.0.0
Errors
Common errors & fixes
cors is not defined
Using ES module import (import cors from 'express-cors') with a CommonJS-only package.
fix
Use require('express-cors') instead: const cors = require('express-cors');
TypeError: app.use() requires a middleware function
Passing incorrect configuration object or forgetting to call cors() as a function.
fix
Ensure you pass the options object to cors(): app.use(cors({ ... }))
Cannot find module 'express-cors'
Package not installed or missing in node_modules.
fix
Run: npm install express-cors
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
express-cors — npm install express-cors · libregistry