Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.3K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda