Skip to main content

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

Comments

  1. I had a look at the details that you mentioned in the content regarding Enable CORS in node js and I believe that the content mentioned in the blog is very description and knowledgeable. I must recommend everyone to read this.
    I was searching for Node js development company and found your blog.
    Synsoft Global
    Thanks for sharing such a great blog.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to get GTU degree Certificate for Pass Out Students in 2016....???

Dear Friends, If your last exam result was declared in 2016 then you are 2016 pass out student so you have to do the procedure for convocation in the next convocation (in the 6th convocation). i.e. next year Jan-2017. Form filling for the same will be start in Oct or Nov-2016 on Official GTU website ( gtu.ac.in --> Student Zone --> Convocation). Currently you cant able to fill up the form of convocation. For more information, kindly visit the "convocation" tab on official GTU website regularly, all the instruction about how to get the certificate are described in detail at there, kindly read it carefully, all the notification regarding convocation will be declared at there. Thanks. Most Important Point for Degree Certificate: URL : www.gtu.ac.in E-Mail : convocation@gtu.edu.in Link for apply: http://www.gtu.ac.in/ Convocation.asp Link for Online Payment: https://www.on...

Construction Safety Presentation

 Hello, It is dangerous for construction activity due to neglect of Safety. Recently, last week two incidents occurred and we lost the lives of labor. Is it injustice? If we are aware about it no one can lost life as well as damage will be also minimize. If you follow regulation, regulation saves life. On dated 12.10.2024 at Kadi, Dist. Mehsana nine men life lost during the excavation activities. and same day at Junagadh Labor fall down from the terrace.  Here, I attached presentation for your reference.  for download:  Click Here Regards, Mahavirsinh G Parmar

Short Course on Innovative Foundation Design Methods for Structures on Expansive Soils at IIT Gandhinagar

  Hello Civil Engineer :  It is great opportunity to join IIT Gandhinagar campus for Short Course on “ Innovative Foundation Design Methods for Structures on Expansive Soils ” being organized by IIT Gandhinagar during  23rd -25th  January, 2025 .  Interested persons may register online through  google form link . Few details are given below. You may refer before apply. Short Course on Innovative Foundation Design Methods for Structures on Expansive Soils To be conducted at  IIT Gandhinagar during 23rd – 25th January, 2025 Course Objectives Foundations on expansive soil sites are one of the most challenging problems facing builders, engineers, and building owners today. Many of the problems result from failure to identify expansive soils on the sites, inadequate design and construction, use of inappropriate foundation systems, and/or improper construction practices. Damage to structures and infrastructure due to heaving of expansive soils is a billion-d...