Running the Dev Servers
A dev server is a program that runs the app during development. It reloads the code each time a file is saved.
Start the API server
Run this command in the server folder.
npm run devThe API address
The API answers at this address.
console.log('http://localhost:3001');The app address
The React app opens at this address.
console.log('http://localhost:5173');Example
console.log('API: http://localhost:3001');
console.log('App: http://localhost:5173');
console.log('Both servers are running.');Key points
- A MERN app needs two dev servers, one per side.
- The API server runs the Express code on a local port.
- The app server runs the React code in the browser.
- A local port is a numbered door on the same machine.
- Both servers must run at the same time.
In this example, the API address prints first. The second line prints the app address. The third line prints a short message. The output shows both dev servers and their addresses.
Note
The API runs on port 3001 and the app runs on port 5173 in this course.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
How many dev servers does a MERN app need while it is being built?