NodeJS + Express: Enable CORS - 10/28/2014

Add this code to your NodeJS script

var express = require('express'),
app = express();

// module to handle cross origin requests
var allowCrossDomain = function(req, res, next) {
   // change the * to the correct domain
   res.header('Access-Control-Allow-Origin', '*');
   // Change this to the methods you want
   res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
   res.header('Access-Control-Allow-Headers', 'Content-Type');

   next();
}
 
// inject the handler into the express pipeline
app.use(allowCrossDomain);

Blog ID: 2014 10-28_Blog_6158