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

90
Views
Why is JSON data sent from server to browser undefined?

I want to make a request to my server with fetch(), and have data returned to be used in the front end app.

here is my route:

    app.get('/game-data', (req, res) => {
    res.json({ data: "test-data" })
})

and here is my request:

button.addEventListener('click', () => {
    fetch('/game-data', {
        headers: {
            'accept': 'application / json',
            'Content-Type': 'application/json'
        }
    })
        .then(response => {
            console.log(response)
            response.json()
        })
        .then(myJson => {
            console.log(myJson)
        })
})

I can see the response object in the first console log, but response.json(), or response.text() are returning undefined.

Please help me see what I am missing!

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

0

You need to return the value to use it in another .then

.then(response => {
        console.log(response)
        return response.json()
    })
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!