0
0
ReactHow-ToBeginner · 3 min read

How to Create React App: Simple Steps to Start Your Project

To create a React app, use the npx create-react-app my-app command in your terminal. This sets up a new React project with all necessary files and dependencies ready to run.
📐

Syntax

The basic command to create a React app is npx create-react-app <app-name>. Here:

  • npx runs the package without installing it globally.
  • create-react-app is the tool that sets up the React project.
  • <app-name> is the folder name for your new app.

After running this, you get a ready-to-use React project folder.

bash
npx create-react-app my-app
💻

Example

This example shows how to create a React app named my-app, start the development server, and see the app in the browser.

bash
npx create-react-app my-app
cd my-app
npm start
Output
Starting the development server... Compiled successfully! You can now view my-app in the browser. Local: http://localhost:3000 The page will reload if you make edits.
⚠️

Common Pitfalls

Common mistakes when creating a React app include:

  • Not having Node.js installed or using an outdated version.
  • Running create-react-app without npx, which may cause errors if the package is not installed globally.
  • Choosing an app name with spaces or special characters, which is invalid.
  • Trying to create a React app inside an existing project folder, which can cause conflicts.

Always check your Node.js version with node -v and use a folder name with only letters, numbers, dashes, or underscores.

bash
Wrong:
npm create-react-app my app

Right:
npx create-react-app my-app
📊

Quick Reference

CommandDescription
npx create-react-app my-appCreate a new React app named 'my-app'
cd my-appGo into the app folder
npm startStart the development server and open the app in browser
npm run buildCreate a production-ready build of the app

Key Takeaways

Use npx create-react-app <app-name> to quickly set up a React project.
Make sure Node.js is installed and updated before creating the app.
Choose a simple, valid folder name without spaces or special characters.
Run npm start inside the app folder to launch the development server.
Avoid creating a React app inside an existing project folder to prevent conflicts.