DEV Community

Cover image for A Beginner's Guide to Getting Started with React
selmon haftom
selmon haftom

Posted on

A Beginner's Guide to Getting Started with React

React is a powerful JavaScript library used for building complex user interfaces. If you're new to React, it can be daunting to know where to start. In this guide, we'll cover everything you need to know to get started with React, from setting up your development environment to building your first app.

1. Install Node.js and npm

Before you can start working with React, you need to have Node.js and npm installed on your computer. Node.js is a JavaScript runtime that enables you to run JavaScript on the server side, while npm is a package manager that makes it easy to install and manage third-party packages.

To install Node.js and npm, go to the Node.js website and download the appropriate installer for your operating system. After the installation, you can verify that Node.js and npm are installed by running the following commands in your terminal:

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

If you see version numbers, you have successfully installed Node.js and npm.

2. Create a New React Project with Create React App

To create a new React project, we recommend using Create React App, a command-line tool that sets up a new React project with minimal configuration. To create a new project, run the following command in your terminal:

npx create-react-app my-app
Enter fullscreen mode Exit fullscreen mode

This command creates a new React project in a folder named my-app. The installation may take several minutes, depending on your internet speed. After the installation is complete, navigate to the project folder by running the following command:

cd my-app
Enter fullscreen mode Exit fullscreen mode

3. Understanding the React Folder Structure

When you create a new React project with Create React App, it generates a folder structure with several files and folders. Here's a brief overview of the most important files and folders:

public: This folder contains static assets such as images, fonts, and the index.html the file that serves as the entry point for your app.

src: This folder contains the source code for your app, including the main index.js file, which renders your app to the page.

node_modules: This folder contains all the third-party packages that your app depends on.

package.json: This file contains information about your app, such as its name, version, and dependencies.

4. Running Your App Locally with npm start

Now that you have a new React project, you can run it locally using the npm start command. This command starts a development server that serves your app and reloads the page whenever you make changes to your code. To start the development server, run the following command:

npm start
Enter fullscreen mode Exit fullscreen mode

This command opens your app in a web browser at http://localhost:3000. You should see a message that says "Welcome to React" on the page.

In this first part of the React for Beginners series, we covered the basics of getting started with React, including installing Node.js and npm, creating a new React project with Create React App, understanding the folder structure of a React project, and running your app locally with npm start. In the next part of the series, we'll cover how to build your first React component. By following these steps, you'll be well on your way to becoming a skilled React developer.

Top comments (0)