Skip to main content

Posts

Showing posts with the label Node JS

Enable CORS in node js - Fix CORS error on node js

 Some time while working on HTTP get or post a request from another application you will get CORS blocked by HTTP and you will not be able to send a request to the server. CORS - Cross-Domain Requests. Simply send the below header to your request to enable CORS.  res.header("Access-Control-Allow-Origin", "*");  If you want to enable all the requests on the server. In your app.js file, you can put below code snippet. var express = require('express'); var app = express(); app.use(function(req, res, next) {   res.header("Access-Control-Allow-Origin", "*");   res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");   next(); }); Github Gist Link