Setting up your environment
Installing Node.js, npm, and creating your first React app
- Course
- React fundamentals
- Lesson
- 2 of 9
- Level
- Beginner
- Reading time
- 15 minutes
Before you can start building with React, you need to set up your development environment. This lesson will guide you through installing the necessary tools.
Prerequisites
Installing Node.js and npm ¶
Node.js is a JavaScript runtime that allows you to run JavaScript outside the browser. npm (Node Package Manager) comes bundled with Node.js and is used to install and manage packages.
Step 1: Download Node.js ¶
Visit nodejs.org and download the LTS (Long Term Support) version for your operating system.
- Download the Windows Installer (.msi) from nodejs.org.
- Run the installer and follow the installation wizard.
- Verify the installation by opening Command Prompt and running:
node --version
npm --versionCreating Your First React App ¶
Now that you have Node.js and npm installed, you can create your first React application using Create React App or Vite.
Using Vite (Recommended) ¶
Vite is the modern, faster alternative to Create React App:
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run devIt runs
http://localhost:5173. Open it in your browser to see your first React application.Using Create React App (Alternative) ¶
npx create-react-app my-react-app
cd my-react-app
npm startUnderstanding the Project Structure ¶
After creating your app, you'll see this folder structure:
my-react-app/
├── node_modules/
├── public/
│ └── index.html
├── src/
│ ├── App.jsx
│ ├── App.css
│ ├── main.jsx
│ └── index.css
├── package.json
└── vite.config.jsThe files you will touch most:
| File | What it does |
|---|---|
src/main.jsx | Entry point of your application |
src/App.jsx | Main React component |
package.json | Project dependencies and scripts |
vite.config.js | Vite configuration file |
Next Steps ¶
Next lesson
With your development environment set up, you're ready to learn about JSX syntax and start writing React components!