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

147
Views
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 answers
Answer question

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 Report

0

adding response.json() will solve your problem

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!