Enabling CORS on a Node.js server can be done using the code snippet below.
This code uses express as the framework for node development.
var express = require('express'); var app = express(); app.use(function(req, res, next) { // add the access control headers res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }); app.get('/', function (req, res) { var data = {}; res.json(data); }); app.get('/download', function(req, res){ var file = __dirname + '/download.tar'; res.download(file); // Set disposition and send it. });
Hope this is helpful!