Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda