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

1.3K
Visualizações
Why can't I call localhost localhost:5000 from localhost:3000 using fetch in react?

My react application running on localhost:3000 and in that I am making a GET request in my code using fetch to localhost:5000/users.

const [users, setUsers] = useState([]);

useEffect(() => {
  fetch('http://localhost:5000/users')
    .then(res => res.json())
    .then(data => setUsers(data))
}, []);

But I'm getting an error called

Access to fetch at 'http://localhost:5000/users' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

It is a much discussed problem. Follow the steps below:

If you are using nodejs or express js for your backend. Install the cors package in your express app.

npm install cors

And, include the following in your index.js file.

var cors = require('cors')

app.use(cors())

That's it. It should work now. Don't forget to restart your node server.

To understand it better, read this article.

over 4 years ago · Santiago Trujillo Relatório

0

It's a CORS problem , Try to use with this way

fetch('http://localhost:5000/users', { mode: 'no-cors' })
over 4 years ago · Santiago Trujillo 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