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

174
Views
Cant get data from express server

I am trying to send a GET request and receive a response on my client side (react).

On my express server:

app.get('/', function (req, res) {
   res.send('Hey, I came from the express server');
})

When I use postman to sent the request I receive a good answer:

enter image description here

So I don't think the problem is with the server.

A problem:

When I try to send the request using react like this:

  const getData = () => {
    fetch("http://localhost:8081", {
      method: "GET",
      mode: 'no-cors'
    }).then(response => console.log(response));
  }

For some reason the response status is 0 and not 200 (I am receiving status code of 200 when checking this request with postman and also on the chrome network tab). In addition, if I try to print response.body it will be null.

The response:

body: (...)
bodyUsed: false
headers: Headers {}
ok: false
redirected: false
status: 0
statusText: ""
type: "opaque"
url: ""
[[Prototype]]: Response

What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to transfer your response to an text or json like:

  const getData = () => {
    fetch("http://localhost:8081", {
      method: "GET",
      mode: 'no-cors'
    }).then(response => response.json()).then(data => console.log(data))
  }

Besides .json() there are even more methods. Its everything written down in the docs. You just need to google it:

https://developer.mozilla.org/en-US/docs/Web/API/Response#methods

about 4 years ago · Juan Pablo Isaza Report

0

You can add a proxy property to your package.json:

"proxy": "http://localhost:8081",

And then just use / as your fetch endpoint.

fetch('/'...
about 4 years ago · Juan Pablo Isaza 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!