React Installation: A Beginner's Guide

Shubham SardaShubham Sarda
5 min read

ReactJS is a popular JavaScript library for building user interfaces. Installing React on your system is straightforward and can be done using tools like Create React App, Set React App and Vite, which streamline the setup process. Additionally, you can use online platforms like StackBlitz to skip the installation entirely and start coding React directly in your browser. Here's a step-by-step guide to get started:


1. Installing React with ‘Create React App’

Create React App is the simplest way to set up a React application without manually configuring tools.

Step 1: Install Node.js

  • Download and install Node.js from nodejs.org. It comes with npm (Node Package Manager), which you’ll need for React.

Step 2: Create a New React App

  • Open your terminal or command prompt and run the following command:

      npx create-react-app my-app
    

    Replace my-app with the name of your project folder.

    • npx ensures you’re using the latest Create React App version.

Step 3: Navigate to Your Project Directory

cd my-app

Step 4: Start the Development Server

npm start

This will launch your app in the browser at http://localhost:3000/.


2. Installing React with ‘Set React App’ 📌

Set React App is a lightweight, opinionated setup for building modern React applications, leveraging Vite for fast bundling and development.

Step 1: Install Node.js

Ensure Node.js is installed on your system.

Step 2: Create a New React App with Set React App

  • Run the following command to create your app:

      npx set-react-app my-app
    

    Replace my-app with your project name. This command initializes a new React project configured with Vite.

Step 3: Navigate to Your Project Directory

cd my-app

Step 4: Start the Development Server

npm start

This will start the Vite dev server on http://localhost:3000/ by default.
Set React App works in the same way as Create React App, with the primary difference being that it uses the .jsx file format instead of .js.

For more details, visit the Set React App npm page.


3. Installing React with Vite

Vite is a faster and more lightweight alternative to Create React App, especially suitable for modern React projects.

Step 1: Install Node.js

Ensure Node.js is installed on your system.

Step 2: Create a New React App with Vite

  • Run the following command to create your app:

      npm create vite@latest my-app
    

    During setup, select React as the framework and JavaScript or TypeScript as per your preference.

Step 3: Navigate to Your Project Directory

cd my-app

Step 4: Install Dependencies

npm install

Step 5: Start the Development Server

npm run dev

This will launch your app in the browser at http://localhost:5173/.


4. Installing React with Next.js

Next.js is a popular React framework that enables server-side rendering and static site generation, providing a robust environment for building React applications.

Step 1: Install Node.js

Ensure Node.js is installed on your system.

Step 2: Create a New Next.js App

  • Run the following command to create your app:

      npx create-next-app my-app
    

    Replace my-app with your project name. This command sets up a new Next.js project with all necessary configurations.

Step 3: Navigate to Your Project Directory

cd my-app

Step 4: Start the Development Server

npm run dev

This will launch your app in the browser at http://localhost:3000/.


5. Using React Online with StackBlitz

If you want to skip local installation and dive straight into coding React, StackBlitz is an excellent online platform. It provides a browser-based development environment, allowing you to run React projects instantly without setting up anything on your system.

Steps to Use React on StackBlitz:

  1. Visit StackBlitz: Go to stackblitz.com.

  2. Create a New React Project:

    • Click on "Create New Project" or search for the React template.

    • Select the React option to start with a pre-configured React environment.

  3. Start Coding:

    • A complete React project is initialized in seconds, with a src folder, App.js, and other familiar files.

    • You can start writing your React code directly in the browser.

  4. Preview Your Application:

    • StackBlitz provides a live preview of your application, visible alongside the editor. Any changes you make are reflected in real-time.

Benefits of StackBlitz:

  • No Setup Hassle: Perfect for quick prototyping or testing ideas without installing Node.js or other tools.

  • Collaboration: Share your project with a link, enabling others to view or edit it in real time.

  • Cross-Device Coding: Work on your project from any device with a web browser.


Which Method Should You Choose?

  • Create React App is ideal for beginners due to its simplicity and wide adoption.

  • Set React App: Combines the simplicity of Create React App with the performance benefits of Vite.

  • Vite is great for faster builds and modern project needs.

  • Next.js: Ideal for building advanced React applications with features like server-side rendering (SSR) and static site generation (SSG).

  • StackBlitz is perfect for quick experimentation or learning React without installation.

Final Thoughts

If you’re just starting, Create React App or Set React App is a safe and beginner-friendly choice. As your needs evolve, consider switching to Vite for performance or Next.js for advanced features. For quick and lightweight development, StackBlitz is a convenient option. No matter which method you choose, React’s flexibility ensures you’ll have the right tools to build amazing applications!

Happy coding! 🎉

0
Subscribe to my newsletter

Read articles from Shubham Sarda directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Sarda
Shubham Sarda