DEV Community

Cover image for Day 2 : Setting up the React Environment
Dipak Ahirav
Dipak Ahirav

Posted on • Edited on

Day 2 : Setting up the React Environment

In our previous blog post, we covered the basics of React.js, including the concept of JSX and how to create and render React components. Today, we'll focus on setting up the React development environment, which is an essential step before diving deeper into the framework.

please subscribe to my YouTube channel to support my channel and get more web development tutorials.

Installing Node.js and Package Managers

React.js is a JavaScript library, and to work with it, you'll need to have Node.js installed on your machine. Node.js is a runtime environment that allows you to run JavaScript outside of a web browser.

Along with Node.js, you'll also need a package manager, such as npm (Node Package Manager) or yarn. These tools help you manage and install the necessary dependencies for your React project.

  1. Install Node.js: Visit the official Node.js website (https://nodejs.org) and download the latest LTS (Long-Term Support) version for your operating system.
  2. Install a Package Manager: You can choose either npm or yarn. If you're using npm, it comes bundled with Node.js. If you prefer yarn, you can install it globally using npm: npm install -g yarn.

Setting up a React Project

Now that you have Node.js and a package manager installed, you can set up a new React project. There are several ways to do this, but we'll focus on two popular methods:

Using create-react-app

create-react-app is a command-line tool provided by the React team that sets up a complete React development environment for you. It includes a development server, build scripts, and a pre-configured project structure.

  1. Open your terminal or command prompt.
  2. Run the following command to create a new React project:
   npx create-react-app my-app
Enter fullscreen mode Exit fullscreen mode
  1. Once the installation is complete, navigate to the project directory:
   cd my-app
Enter fullscreen mode Exit fullscreen mode
  1. Start the development server:
   npm start
Enter fullscreen mode Exit fullscreen mode

This will start the development server and open your app in the default web browser.

Using Vite

Vite is a newer and faster alternative to create-react-app. It provides a more lightweight and opinionated setup for React projects.

  1. Open your terminal or command prompt.
  2. Install Vite globally using npm or yarn:
   npm install -g create-vite
Enter fullscreen mode Exit fullscreen mode
  1. Create a new Vite-based React project:
   create-vite my-app --template react
Enter fullscreen mode Exit fullscreen mode
  1. Navigate to the project directory:
   cd my-app
Enter fullscreen mode Exit fullscreen mode
  1. Install the dependencies:
   npm install
Enter fullscreen mode Exit fullscreen mode
  1. Start the development server:
   npm run dev
Enter fullscreen mode Exit fullscreen mode

This will start the Vite development server and open your app in the default web browser.

Project Structure

Both create-react-app and Vite provide a pre-configured project structure for your React application. The main files and directories you'll find in a typical React project are:

  • src/: This directory contains the source code of your application.
    • App.js: The main component of your application.
    • index.js: The entry point of your application.
  • public/: This directory contains the HTML file that will serve as the root of your application, as well as other static assets.
  • package.json: This file manages the dependencies and scripts for your project.

Conclusion

In this blog post, you've learned how to set up the React development environment by installing Node.js and a package manager, as well as creating a new React project using create-react-app and Vite. You've also explored the basic project structure that these tools provide.

Series Index

Part Title Link
1 Day 1: React js Basics Read Part 1
2 Day 2 : Setting up the React Environment Read Part 2
3 Day 3: React Components Read Part 3
4 Day 4: React State and Hooks Read Part 4
5 Day 5: Conditional Rendering and Lists in React Read Part 5
6 Day 6: Advanced React Concepts Read Part 6
7 Day 7: Building a React Project 🏗️ Read Part 7
8 Day 8: Advanced React Topics Read Part 8

With the development environment set up, you're now ready to dive deeper into React.js concepts, such as components, state management, and more. Stay tuned for our next blog post, where we'll explore these topics in detail.

Top comments (5)

Collapse
 
neurabot profile image
Neurabot

Enlightened. Discover that React would requiere Node. Cool.

Collapse
 
akinlabi_tobiabraham_859 profile image
Akinlabi Tobi Abraham

Thank you for this . Can I have day 3

Collapse
 
dipakahirav profile image
Dipak Ahirav

Thank you so much for your kind words and feedback! 🙏 I'm thrilled to hear that you found the post helpful. Your support means a lot to me. If you enjoyed this post, please consider subscribing to my YouTube channel devDive with Dipak for more content. Don’t forget to share it with your friends and help spread the word. Your support helps me to continue creating valuable content. Thanks again! 😊

Collapse
 
dipakahirav profile image
Dipak Ahirav

Next Part -> Part - 3

Collapse
 
dipakahirav profile image
Dipak Ahirav

@akinlabi_tobiabraham_859 thanks for response, Yes i am going to publish day 3 post tomorrow.