Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
Why is node fetch not working (node-fetch) in javascript

I'm trying to fetch data from a URL with fetch but it doesn't work. I imported node-fetch module by typing:

const fetch = require("node-fetch");

And here's where I use it:

async function getUrl(url) {
    let d = await fetch(url);
    let j = d.json();
    return j;
}

getUrl(myURL);

I also have the 'npm install node-fetch' to the terminal and it says there's no such file or directory.

Do you know where I am having the issue?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Once fetch is imported this works (in browsers fetch is built-in):

async function getUrl(url) {
    let d = await fetch(url);
    let j = await d.json();
    return j;
}

// example JSON API
const myURL = 'https://reqres.in/api/users';

// IIFE needed for demonstration purposes
(async function(){
  const data = await getUrl(myURL);
  console.log(data);
})()

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda