User Agents

Web browsers and everyday web tech, explained

How to View React App in Browser: Quick Start

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To view your React app in a browser, you run a development server that compiles your code and serves it locally. The default command is npm start (or yarn start), which opens http://localhost:3000 automatically. This guide covers the exact steps for both newly created and existing React projects, plus common pitfalls and fixes.

What You'll Need

  • Node.js (version 14 or later recommended) installed on your computer. Check with node -v.
  • npm or yarn package manager (npm comes with Node.js).
  • A React project folder — either created with create-react-app or set up manually (e.g., with Vite).
  • A code editor (optional but helpful) like VS Code.

Step-by-Step

  1. Open a terminal (Command Prompt, PowerShell, or Terminal) in your project's root directory. The root directory is the folder containing package.json.
  2. Install dependencies (if not already done). Run npm install or yarn install. This creates a node_modules folder. Skip if you just ran create-react-app.
  3. Start the development server. Run npm start (or yarn start). For Vite projects, the command is npm run dev.
  4. Wait for the compilation. You'll see output like "Compiled successfully!" or "VITE ready". The terminal will display a local URL (usually http://localhost:3000 for Create React App, or http://localhost:5173 for Vite).
  5. Open the browser. If it doesn't open automatically, manually type the URL from the terminal into your browser's address bar. For Create React App, it's http://localhost:3000.
  6. View your app. You should see the default React welcome page (or your own components if you've edited the code). Any changes you make to the source files will hot-reload automatically.
  7. Stop the server when done. Press Ctrl+C in the terminal (or Cmd+C on Mac) and confirm with y if prompted.

Common Mistakes

  • Running the command in the wrong folder — if you're not in the project root, npm start will fail with "missing script: start".
  • Forgetting to install dependencies — running npm start before npm install gives an error about missing modules.
  • Port already in use — if port 3000 is occupied, the server will prompt you to use another (e.g., 3001). Accept it or close the other process.
  • Using the wrong command for Vite — Vite projects use npm run dev, not npm start.
  • Editing files in public/ instead of src/ — changes to public/index.html may not trigger hot reload; you might need to refresh manually.

Tips

  • Use the browser's developer tools (F12) to inspect the React component tree — install the React DevTools extension for Chrome or Firefox to see props and state.
  • Keep the terminal visible while developing; errors and warnings appear there and are often more detailed than in the browser console.
  • Use npm run build for production — this creates an optimized build folder that you can serve with any static server. But for daily development, npm start is faster.
  • Set a custom port if needed: npm start -- --port 5000 (for Create React App) or set PORT environment variable.
  • If hot reload seems stuck, refresh the browser manually. Sometimes the websocket connection drops.

Troubleshooting

  • "'npm' is not recognized as internal or external command" — Node.js is not installed or not in your PATH. Download and install Node.js from nodejs.org, then restart your terminal.
  • "Module not found: Can't resolve 'react'" — dependencies are missing. Run npm install again.
  • Browser shows a blank white page — check the browser console (F12) for errors. Common causes: syntax error in your code, or you're running the app from a different directory than the project root.
  • Port 3000 is already in use — the terminal will ask "Would you like to run the app on another port instead?" Type y. Alternatively, close the other process (e.g., another React app).
  • Changes not appearing after editing — make sure you're editing files in src/, not the build folder. Also check that the terminal shows "Compiled successfully" after saving.
  • App loads but shows an error overlay — read the error message in the red overlay; it usually points to the exact file and line. Fix the error and save; the overlay clears.

Frequently Asked Questions

Why does my browser open to a different port than 3000?

If port 3000 is already in use, Create React App automatically uses the next available port (3001, 3002, etc.). The terminal will show the correct URL.

Can I view my React app on my phone?

Yes. Ensure your phone and computer are on the same Wi-Fi. In the terminal, you'll see a "Network" URL like http://192.168.1.5:3000. Enter that on your phone's browser.

What is the difference between npm start and npm run build?

npm start runs a development server with hot reload, optimized for coding. npm run build creates a production-ready static bundle in a build folder that you can deploy to a web server.

How do I view my React app if I'm using Vite instead of Create React App?

For Vite, run npm run dev (or yarn dev). The terminal will show a local URL, usually http://localhost:5173.

Why does my app show a blank page after I open it?

Check the browser's developer console for errors. A common cause is an uncaught exception in your JavaScript. Also verify that your index.js correctly renders the root component to the root element.

Do I need to restart the server after editing code?

No. The development server automatically recompiles and reloads the page when you save changes. If it doesn't, try refreshing manually or restarting the server.