Skip to main content

🛠️ Setting Up a React Development Environment

Good tools get out of your way so you can focus on building. In this lesson you'll install Node.js the reliable way, pick a package manager, tune VS Code for React, and scaffold a running app with Vite — the fast, modern replacement for the now-deprecated Create React App.

🎯 Learning Objectives

By the end of this lesson, you will be able to:

  • Install Node.js using a version manager and explain why React needs it
  • Choose between npm, pnpm, and Yarn and run their equivalent commands
  • Configure VS Code with the extensions and settings that make React productive
  • Describe the roles of build tools — Babel/SWC, the bundler, ESLint, and Prettier
  • Scaffold, run, and understand the structure of a Vite + React project

Estimated Time: 35–45 minutes  •  Difficulty: Beginner

Hands-on: Create a running React app with Vite and make your first live edit.

In This Lesson

What's in a React Environment?

A React "development environment" is really a small toolchain working together. You don't assemble each piece by hand — a scaffolding tool wires most of it up for you — but knowing what each part does turns cryptic errors into obvious fixes.

flowchart TD A[Your React environment] --> B[Node.js + a package manager] A --> C[Code editor: VS Code] A --> D[Build tool: Vite] A --> E[Browser + React DevTools] D --> D1[Babel / SWC — compiles JSX] D --> D2[Bundler — Rollup / esbuild] D --> D3[ESLint — finds problems] D --> D4[Prettier — formats code]
🏗️ A construction-site analogy: Node.js is the generator powering the whole site. npm is the supply chain delivering materials (libraries). The build tools are your heavy machinery. And VS Code is the site office where the plans are drawn. You wouldn't pour concrete before the power's on — so we start with Node.

Installing Node.js the Right Way

React tooling runs on Node.js, a JavaScript runtime, and ships with npm (Node Package Manager). It may feel odd to install a "server" technology for a browser app, but the build tools, dev server, and package installer all run on Node.

📖 Why Node.js for a frontend app?

Build tools like Vite and Babel are Node programs. npm downloads the thousands of libraries in the React ecosystem. Your dev server (with hot reloading) is a Node process. And most test runners execute on Node too.

Use a version manager (recommended)

You could download an installer from nodejs.org and pick the LTS (Long-Term Support) build. But a version manager is better: it lets you switch Node versions per project, which matters the moment you juggle more than one codebase.

macOS / Linux — nvm

# Install nvm (check github.com/nvm-sh/nvm for the latest version)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# Restart your terminal, then install and use the latest LTS
nvm install --lts
nvm use --lts

Windows — nvm-windows or fnm

# After installing nvm-windows (github.com/coreybutler/nvm-windows)
nvm install lts
nvm use lts

Verify the installation

node --version   # e.g. v22.11.0
npm --version    # e.g. 10.9.0

⚠️ Pick an LTS version

Even-numbered Node releases (18, 20, 22…) are LTS and supported for years — use these for real work. Odd-numbered "Current" releases get the newest features but shorter support. When in doubt, run nvm install --lts.

Package Managers

A package manager installs, updates, and tracks the libraries your project depends on, recording exact versions in a lock file so every machine gets identical installs. Three are common today:

FeaturenpmpnpmYarn
Ships with Node.js✅ Yes❌ Install separately❌ Install separately
SpeedGoodExcellentVery good
Disk usageStandardLowest (shared store)Standard
Lock filepackage-lock.jsonpnpm-lock.yamlyarn.lock

npm comes free with Node and is perfect for learning — this course uses it. pnpm is a popular faster alternative that saves disk space by sharing packages between projects. Install either extra manager with a one-liner:

# Enable pnpm via Corepack (bundled with modern Node)
corepack enable
corepack prepare pnpm@latest --activate

# Or install Yarn the same way
corepack prepare yarn@stable --activate

Command cheat sheet

Tasknpmpnpm
Install all dependenciesnpm installpnpm install
Add a packagenpm install reactpnpm add react
Add a dev dependencynpm install -D vitestpnpm add -D vitest
Run a scriptnpm run devpnpm dev
Remove a packagenpm uninstall reactpnpm remove react

⚠️ Don't mix package managers in one project

Pick one per project. Mixing npm install and pnpm install creates conflicting lock files and confusing bugs. Commit your lock file to Git so teammates get the exact same dependency tree.

Setting Up VS Code

Visual Studio Code is the de-facto editor for React thanks to its JavaScript/TypeScript support and huge extension library. Download it from code.visualstudio.com.

Essential extensions

ExtensionWhy you want it
ESLintFlags bugs and bad patterns as you type
PrettierAuto-formats code on save for a consistent style
ES7+ React/Redux snippetsType rafce to scaffold a whole component
Auto Rename TagRenames the matching JSX closing tag automatically
Error LensShows errors inline on the offending line

Recommended settings

Open the command palette (Ctrl/Cmd + Shift + P → "Preferences: Open User Settings (JSON)") and add:

{
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.tabSize": 2,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit"
  },
  "emmet.includeLanguages": { "javascript": "javascriptreact" },
  "javascript.updateImportsOnFileMove.enabled": "always"
}

💡 Format-on-save is a quiet superpower

With formatOnSave plus Prettier, you stop thinking about indentation and quotes entirely — every save cleans the file. Code reviews then focus on logic, not spacing.

The Build Tools Explained

Browsers can't run JSX directly, and shipping hundreds of separate files is slow. Build tools transform and package your code. You rarely configure them by hand anymore, but here's what each one does:

ToolJob
Babel / SWCCompile JSX and modern JS into browser-compatible JavaScript
Bundler (Rollup / esbuild)Combine and optimize modules into a few efficient files
ESLintStatic analysis that catches likely bugs and enforces rules
PrettierOpinionated formatter for one consistent code style

The compile step is what turns friendly JSX into the plain function calls a browser understands:

// What you write (JSX)
const element = <h1 className="title">Hello, world!</h1>;

// What the compiler produces (simplified)
const element = React.createElement(
  'h1',
  { className: 'title' },
  'Hello, world!'
);
📚 A publishing analogy: your source code is the manuscript; Babel is the translator; the bundler is the typesetter arranging everything into the finished book; ESLint is the copy-editor catching mistakes; and Prettier is the house style guide. The production build is the printed book, ready to ship.

✅ Vite gives you all of this for free

Vite bundles esbuild (blazing-fast compilation) and Rollup (optimized production builds), and the React template pre-wires ESLint. You get the whole toolchain from a single command — no manual Webpack config.

Scaffolding with Vite

For years the default was Create React App (CRA). It is now deprecated — the React team no longer recommends it. The modern choice for a client-side app is Vite: near-instant startup, lightning-fast hot reloading, and minimal config. (For full-stack apps with server rendering, reach for Next.js instead.)

Step 1 — create the project

# npm
npm create vite@latest my-react-app -- --template react

# pnpm
pnpm create vite my-react-app --template react

# TypeScript variant
npm create vite@latest my-react-app -- --template react-ts

Step 2 — install dependencies

cd my-react-app
npm install

Step 3 — start the dev server

npm run dev

You'll see something like:

  VITE v6.0.0  ready in 312 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

Open http://localhost:5173/ in your browser. Now edit src/App.jsx, change some text, and save — the page updates instantly without a full reload. That's Hot Module Replacement (HMR), and it's the single biggest quality-of-life feature in modern frontend work.

ToolBest forStatus
ViteClient-side single-page apps; learningRecommended
Next.jsServer rendering, routing, full-stackRecommended for production
Create React AppDeprecated — avoid

The Project Structure

Vite generates a clean, minimal layout. Here's what each part is for:

my-react-app/
├── node_modules/      # installed dependencies (never edit; git-ignored)
├── public/            # static assets served as-is
├── src/               # your application code lives here
│   ├── assets/        # images imported by components
│   ├── App.jsx        # the root React component
│   ├── App.css        # styles for App
│   ├── index.css      # global styles
│   └── main.jsx       # entry point — mounts React into the page
├── index.html         # the single HTML page Vite serves
├── package.json       # dependencies and npm scripts
├── vite.config.js     # Vite configuration
└── eslint.config.js   # ESLint rules

The two files that matter most

index.html holds a single mount point — an empty <div> React fills in:

<body>
  <div id="root"></div>
  <script type="module" src="/src/main.jsx"></script>
</body>

src/main.jsx is where React takes over that div and renders your App:

import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App.jsx';
import './index.css';

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <App />
  </StrictMode>
);

📖 Note the modern API

This uses createRoot from react-dom/client — the React 18+ entry point that enables concurrent features. The older ReactDOM.render is deprecated. StrictMode is a development-only helper that surfaces potential problems early.

Hands-on Exercise

🏋️ Build and Personalize Your First React App

Objective: Go from zero to a running, edited React app.

Instructions:

  1. Confirm Node is installed: node --version (should be an LTS like v20 or v22).
  2. Scaffold a project: npm create vite@latest hello-react -- --template react
  3. cd hello-react, then npm install, then npm run dev.
  4. Open src/App.jsx and replace the default heading with a greeting that includes your name.
  5. Save and watch the browser update instantly (no manual refresh).
  6. Run npm run build, then npm run preview, and note the difference between the dev and production builds.
💡 Hint

In App.jsx, delete the boilerplate inside the returned JSX and drop in a single <h1>. Keep everything inside one parent element (a <div> or a <>…</> fragment) or React will complain.

✅ Example solution
import './App.css';

function App() {
  const name = 'Ray';
  return (
    <div className="app">
      <h1>👋 Hello, {name}! Welcome to React.</h1>
      <p>My development environment is up and running.</p>
    </div>
  );
}

export default App;

Notice the {name} expression — that's JSX embedding a JavaScript value, which is exactly what the next lesson dives into.

🎯 Quick Quiz

Question 1: Why does a browser-only React app still require Node.js?

Question 2: Which tool should you use to start a new client-side React project today?

Question 3: What does Hot Module Replacement (HMR) give you?

Troubleshooting

Almost every beginner hits one of these. Keep this list handy:

⚠️ Common setup snags

"command not found: npm" — Node isn't installed or isn't on your PATH. Reinstall via nvm and restart the terminal.

Port 5173 already in use (EADDRINUSE) — another process holds the port. Stop it, or set a new port in vite.config.js: server: { port: 3000 }.

ESLint not working in VS Code — make sure the ESLint extension is installed and reload the window (Ctrl/Cmd + Shift + P → "Reload Window").

HMR stopped updating — usually a syntax error broke the build. Check the terminal and browser console, fix the error, and it resumes.

Summary & Quiz

🎉 Key Takeaways

  • Install Node.js (LTS) with a version manager like nvm so you can switch versions per project.
  • npm ships with Node and is great for learning; pnpm and Yarn are faster alternatives.
  • Tune VS Code with ESLint, Prettier, and format-on-save for a smooth workflow.
  • Build tools (Babel/SWC, bundler, ESLint, Prettier) are bundled into Vite so you rarely configure them by hand.
  • Use Vite to scaffold client-side apps — Create React App is deprecated.

📚 Further Reading

🚀 What's Next?

Your environment is ready and an app is running. Next we'll dig into the syntax you'll use to describe every UI in React: JSX — how it works, how it differs from HTML, and how to embed live JavaScript inside your markup.

🎉 You're set up!

A working toolchain is a milestone every developer remembers. Now let's learn to speak JSX.