Getting Started with React
To start working with React, you first need to set up a proper development environment. React does not run directly in the browser, so tools like Node.js, npm, and a build tool are required to create and manage a React application.
In this section, you will learn how to create and run your first React project step by step.
Prerequisites
Before getting started, make sure you have the following:
Basic knowledge of HTML, CSS, and JavaScript
Node.js installed on your system
npm (Node Package Manager) available
npm comes bundled with Node.js, so installing Node.js is usually enough.
Check Node.js Installation
First, confirm whether Node.js is already installed on your system. Open your terminal or command prompt and run:
node -v
If Node.js is installed, it will display a version number, for example:
v22.15.0
If no version appears, you need to install Node.js before continuing.
Setting Up the React Environment
To create a React application, we use a build tool that helps with development, bundling, and fast reloading.
In this tutorial, we will use Vite, which is known for its speed and simplicity.
Install Vite
To install Vite globally, run the following command:
npm install -g create-vite
After successful installation, you will see a message similar to:
added 1 package in 649ms
This means Vite has been installed correctly.
Create a React Application
Now, create a new React project using the command below:
npm create vite@latest my-react-app -- --template react
If the terminal asks for permission, press y and hit Enter to continue. Once the process finishes, your React project will be ready.
Install Project Dependencies
Move into your project directory:
cd my-react-app
Then install all required dependencies by running:
npm install
This command downloads and sets up everything needed for your React application to work properly.
Run the React Application
You are now ready to run your first React app.
Start the development server using:
npm run dev
After a few seconds, you will see an output similar to this:
Local: http://localhost:5173/
Open this URL in your browser to view your React application.
Summary
To get started with React, you need Node.js, npm, and a project setup tool like Vite. Once the environment is ready, you can create a React application, install dependencies, and run it locally in just a few steps.