cors is a Node.js middleware for Express and Connect that sets CORS response headers to control which origins can read responses from your server.
The middleware addresses the need to enable cross-origin requests in web applications by setting the appropriate HTTP response headers that browsers use to enforce CORS policy. It clarifies an important distinction: the middleware sets headers but does not block requests—CORS enforcement happens in the browser itself. Non-browser clients like curl, Postman, or server-to-server requests ignore CORS headers entirely. The tool supports both simple and complex CORS scenarios, including pre-flight OPTIONS requests for requests using non-standard HTTP verbs or custom headers.
Developers should choose this middleware if they are building Express or Connect applications that need to serve requests from different origins. It suits any API or web service where browser-based clients need to access resources across domain boundaries. The middleware offers flexible configuration through static options, dynamic origin validation via callback functions, and per-request customization. Dynamic origin validation enables loading allowed origins from a database or other backing datasource, making it suitable for applications with complex access control requirements.
The project maintains active engagement with its user base through documentation that addresses common misconceptions about how CORS works. The README includes detailed configuration options and multiple usage patterns ranging from enabling all CORS requests globally to configuring specific routes with custom settings. The documentation emphasizes the distinction between what the middleware does—setting headers—and what browsers do with those headers, helping developers avoid misunderstanding CORS behavior.