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

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 successfully” Step: 4 Then Click “OK” on dialog box.

Online application for receiving Degree/Diploma Certificate (Convocation- VI)

Last Date: 26 th Dec, 2016 (Extend) The Degree/ Diploma Certificate Registration Start. Pay Online Fee at SBI: Click Here (Before submit form Pay fee online and note down transaction number.) Apply Online: Click Here:   Before apply online, Read all instructions Carefully. General Instructions| Instructions In GUJARATI An applicant has to fill correct data so that Degree/Diploma Certificate can be printed and delivered correctly. An applicant has to pay the fees of Rs. 500/- for Degree, 300/- for Diploma and 1000/- for Ph.D. certificates in any SBI branch and Rs. 200/- additional if you want to be a member of GTU’s Alumni Association. Please fill the separate Challan for both (Convocation Degree/Diploma Certificate and GTU’s Alumni Association (if you want to be a member of GTU’s Alumni Association)) fees. Please read carefully Fee Payment instruction. Please write SBI Collect Reference N