DEV Community

Cover image for Day 2: Setting Up Your Development Environment - ReactJS
Haque.
Haque.

Posted on • Updated on

Day 2: Setting Up Your Development Environment - ReactJS

Welcome to Day 2 of the "30 Days of ReactJS" challenge! Today, we'll set up your development environment to start building React applications. The tools we choose today will make your development process smoother and more efficient.

Why Setting Up the Right Environment Matters

Before diving into code, it's essential to have a properly configured environment. Imagine you're about to bake a cake. Before you start mixing ingredients, you'd want to ensure you have all the right tools: a mixing bowl, a whisk, an oven preheated to the right temperature, etc. Similarly, in web development, setting up the right tools from the beginning will save you time and headaches later.

What is Vite?

For our development environment, we'll use Vite. Vite (pronounced "veet") is a fast and modern build tool that offers an excellent development experience for ReactJS. It’s known for its speed and simplicity, making it perfect for both beginners and seasoned developers.

Step-by-Step Guide to Setting Up Vite

Let’s go through the steps to set up your ReactJS development environment using Vite.

1. Install Node.js and npm

First, ensure that you have Node.js installed on your computer. Node.js is a JavaScript runtime that allows you to run JavaScript code outside of a browser. Along with Node.js, you'll also get npm (Node Package Manager), which we'll use to manage our project dependencies.

  • Check if Node.js is installed: Open your terminal (Command Prompt, PowerShell, or Terminal on macOS/Linux) and type:
node -v
Enter fullscreen mode Exit fullscreen mode

If Node.js is installed, you’ll see the version number. If not, you can download it from nodejs.org.

  • Check npm version: To check if npm is installed, type:
npm -v
Enter fullscreen mode Exit fullscreen mode

2. Create a New React Project with Vite

Once Node.js and npm are ready, we can create a new React project using Vite. Follow these steps:

  • Step 1: Open your terminal: Navigate to the directory where you want to create your project.
  • Step 2: Run the following command:
npm create vite@latest
Enter fullscreen mode Exit fullscreen mode
  • Step 3: Choose your project name: After running the command, you’ll be prompted to enter your project’s name. For example, you can name it my-react-app.
  • Step 4: Select your framework: Vite will ask you to select a framework. Choose React from the list.
  • Step 5: Select the variant: When prompted to select a variant, choose JavaScript.
  • Step 6: Navigate to your project directory:
cd my-react-app
Enter fullscreen mode Exit fullscreen mode
  • Step 7: Install dependencies:

3. Run Your React Project

Now that the project is set up, let’s run it to ensure everything works correctly.

  • Step 1: Start the development server:
npm run dev
Enter fullscreen mode Exit fullscreen mode
  • Step 2: Open your browser: After running the command, you’ll see an output like this:
VITE v3.0.0  ready in 150 ms

Local:   http://localhost:3000/
Network: http://192.168.1.100:3000/
Enter fullscreen mode Exit fullscreen mode
  • Step 3: Visit the URL: Open http://localhost:3000/ in your browser. You should see the default Vite React template page.

Real-Life Example: Setting Up Your Workspace
Think of this process like setting up a new workspace in your office. You've got your desk (Node.js), your tools (npm), and your project files (React app). Now, you’re ready to start working!

What’s Next?

Now that your development environment is set up, you're ready to start building with React! Tomorrow, we’ll dive into JSX and how React renders elements on the page.

Remember, setting up the environment is just the beginning. With a strong foundation, you can now focus on writing clean, efficient code as we progress through the challenge.

Final Thoughts

Getting your environment right from the start ensures a smooth development experience. With Vite, you’ll benefit from faster builds and instant feedback as you code, making your ReactJS learning journey more enjoyable.

Day 3: Understanding JSX and Rendering Elements

Top comments (0)