How does a React app call an Express API?

MERN: connecting React and the API · Freshers

Model answer

With fetch or axios from an event handler or effect (or TanStack Query): fetch('/api/jobs'). During development a Vite proxy forwards /api to the Express port to avoid CORS. In production, serve both from the same domain or enable CORS with a specific allowed origin.

Learn this topic

useEffect and Fetching Data from Your API: Loading, Errors and Cleanup in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions