Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
make post call to local express server in react

I want to make a post call to a local express server running on port 8001 with axios in my react code like below:

axios.post('http://localhost:8001/enterInfo',{headers: { 'crossDomain': true }}, payload)
        .then((response) => {
            this.setState({
                saved:true
            })
        })

My express server is listening on port 8001. and i have written a post method in my express server:

app.post('/postUrl', (req, res) => {
console.log(req.body);
res.send('111');
});

but when i make the call from the react ui, it is giving this error:

XMLHttpRequest cannot load http://localhost:8001/enterInfo. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You have to enable cross-origin resource sharing on your server.

Check this package :

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

app.post('/postUrl', (req, res) => {
   console.log(req.body);
   res.send('111');
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!