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

145
Vistas
How to Fetch from my local host? Connect React.js to Node.js

Creating my first MERN application and connected the frontend to the backend.

Taking baby steps and trying to simply call the already existing "books" in my mongo database.

Heres what I have

 const fetchingFunction = () => {

   fetch('http://localhost:5000/books', {
     method: "GET",
     headers: {
       "Content-Type": "application/json",
       'Accept': 'application/json'
     }
   }).then(function(response) {

      response.json();

   }).then(data => console.log(data))

 }

I keep getting the error


Uncaught (in promise) SyntaxError: Unexpected token h in JSON at position 0
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to return the response.json().

 const fetchingFunction = () => {

   fetch('http://localhost:5000/books', {
     method: "GET",
     headers: {
       "Content-Type": "application/json",
       'Accept': 'application/json'
     }
   }).then(function(response) {

      return response.json();

   }).then(data => console.log(data))

 }
about 4 years ago · Juan Pablo Isaza Denunciar

0

adding response.json() will solve your problem

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