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

GTU PMMS 8th Semester Team Registrations Steps (Update on 30/01/2016)

PMMS portal for semester eight project activities is made live   on 29.01.2016     Step: 1 Open any browser & in address bar type   http://projects.gtu.ac.in/_layouts/15/GTUPMMS/GTULoginPage.aspx Here, we use Mozilla Firefox in this example. (Don’t use your mobile browser) Step: 1  After opening PMMS page enter your user name & password. Then click on login as shown in above image. Step: 2 After click on login you show this type of image and show the message “This activity has not been allowed” Step: 2  Click on move to 8 th   Semester as shown above image. Step: 3 After clicking on Move to 8 th   Semester new window will be open. Example of this new window    is shown below. Step: 3 Again click on Move to 8 th   Semester as shown above image. Step: 4 After successfully step 3 you will show successfully message as shown below image. “Move to semester 8 has been completed success...