Corser

2.0.1 · abandoned · verified Wed Apr 22

Corser is a highly configurable middleware for Node.js designed to handle Cross-Origin Resource Sharing (CORS). It offers a flexible approach to managing CORS preflight requests and setting appropriate response headers, supporting both static whitelists for allowed origins and dynamic origin checking through a callback function. The package's current stable version is 2.0.1, released in August 2016. Due to the lack of updates since then, its release cadence is effectively non-existent, indicating an abandoned or legacy status despite an 'active' project badge from its active development period. Its key differentiators at the time included robust compatibility with Connect and Express middleware, as well as plain Node.js `http` servers, providing granular control over CORS policies for various server setups. Developers should be aware of its CommonJS-only nature and lack of ongoing maintenance.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to integrate Corser as middleware within an Express.js application, allowing all cross-origin requests by default.

const express = require('express');
const corser = require('corser');

const app = express();

// Configure Corser to allow all origins by default.
// For production, specify a whitelist: corser.create({ origins: ['http://localhost:3000'] })
app.use(corser.create());

app.get('/', function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Nice weather today, huh?');
});

app.listen(1337, () => {
    console.log('Server listening on http://localhost:1337');
});

// To run this example:
// 1. npm install express corser
// 2. node your_script.js

view raw JSON →