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

128
Views
How to use fetch inside GET request and render those result?

I'm using express router in Node and I'm trying to render a page with some data which I get from fetching from an API. However, I get absolutely no results back and it's not the API fault. I checked in console manually and it returns results as expected.

Here's my code:

router.get('/dashboard', ensureAuth, async (req, res) => {
    try {
        const resp = await fetch("https://api.tvmaze.com/shows?page=1")
        const respData = await resp.json()

        res.render('dashboard', {
            name: req.user.firstName,
            image: req.user.image,
            shows: respData
        })
    } catch (error) {
        res.render('dashboard', {
            name: req.user.firstName,
            image: req.user.image
        })
    }

}) 

EDIT: Here's the view which is being rendered:

<body>
        {{#if shows}}
        {{#each shows}}
        <img src="{{image.original}}" alt="{{name}}" />
        <div class="movie-info">
            <h3>{{name}}</h3>
            <span>{{weight}}</span>
        </div>
        {{/each}}
        {{else}}
        <p>No shows available.</p>
        {{/if}}
</body>

I've searched online but I can't find an explanation for where the issue lies here. If this is a duplicate, please redirect me to the original. Thanks.

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

0

You can't use fetch inside node because it's only available in the browser. If you want to make an HTTP request from a node app use axios or node-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!