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

Short course on Innovative Designs for Foundations on Expansive Soils and Stabilization of Unsaturated Slopes| Feb 02-04, 2026

Short Course on Innovative Designs for Foundations on Expansive Soils and Stabilization of Unsaturated Slopes to be organised during  02nd – 04th February 2026  at Indian Institute of Technology Gandhinagar Palaj, Gandhinagar- 382355, Gujarat, India. Foundations on expansive soil sites are one of the most challenging problems in geotechnical design. 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-dollar issue. Another challenge faced by geotechnical designers is stabilization of unsaturated slopes, especially related to landslides and mine tailings, where innovative solutions are required to manage slopes against rainfall induced failures.  This short course is intended to provide geotechnical, structural, and construction engineers and ...

πŸ“© REGISTRATION OPEN – TECHNICAL EXPERT SESSION ON INDIA’S TALLEST TOWER (MINERVA) DESIGN AND CHALLENGES

πŸ“© REGISTRATION OPEN – TECHNICAL EXPERT SESSION ON INDIA’S TALLEST TOWER (MINERVA) DESIGN AND CHALLENGES Knowledge Studio – Neha Consultant in association with Wonder Cement Limited as knowledge Partner Excellent opportunity for Structural Engineers, Architect ,Technocrat and Civil Engineers of Gujarat invites you to attend the Technical Expert Session on πŸ™ Architectural & Structural Challenges of India’s Tallest Tower & 🎯 *Grand Finale – Concrete Catalyst 2026 πŸ“ Venue: B.N.B. Hall, CEPT University, Ahmedabad πŸ“… Date: 15th March 2026 πŸ•” Time: 5:00 PM onwards πŸŽ“ Registration Charges: • Students – ₹50 • Professionals – ₹100 • ⁠Registration is mandatory πŸ”— Kindly register through the link below: πŸ‘‰ https://rzp.io/rzp/OCprta6I Followed by Networking Dinner. We look forward to your presence Warm Regards Nitesh Shah Director Knowledge Studio – Neha Consultant (run by Soulful Joy Trust)  

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...