React Foundations / Start Here

Set up Node.js and run your first React app

Lesson 2 of 35. Open to read. No account needed.

By the end of this lesson a React page will be running on your own computer, and you will have changed it and watched the change appear. Along the way you install the one tool the whole course depends on, Node.js, and create the folder where all your practice work will live.

What You Are Setting Up

A React app is JavaScript that runs in the browser. You still need tools on your computer to write it comfortably:

  • Node.js runs JavaScript outside the browser. The course's tools are JavaScript programs, so they need it.
  • npm, installed with Node.js, downloads packages (other people's published code, such as React itself) from the public npm registry and runs your project's commands.
  • Vite is a build tool. During development it runs a small web server on your computer, the dev server, that turns your source files into something the browser can load and updates the page as you edit. For release it produces optimised files, which a later lesson covers.

React's own documentation recommends a framework, such as Next.js or React Router, for new production apps, because frameworks add routing, data loading and server rendering. It describes starting from a build tool like Vite as the way to learn how React itself works, which is this course's aim. Older tutorials may use a tool called Create React App; the React team deprecated it for new apps in February 2025, so do not use it here.

The Terminal Commands You Need

Everything in this lesson happens in a terminal: Terminal on macOS, a shell on Linux, or PowerShell (or Windows Terminal running PowerShell) on Windows. You need four things:

TaskCommandNotes
Show the current folderpwdWorks in all three
List what is in itlsWorks in all three
Make a foldermkdir nameWorks in all three
Move into a foldercd name; cd .. goes up one levelWorks in all three

A long-running command, like the dev server, keeps the terminal busy until you stop it with Ctrl+C (on macOS too: Control, not Command). If you have never used a terminal, practise these four commands in your home folder before going on. These four commands are all the terminal knowledge this course uses; the separate Linux Foundations course goes further, but is not needed here.

Step 1: Install Node.js

Open a terminal and check whether Node.js is already installed:

node --version
npm --version

Illustrative output from a supported setup (your numbers may be higher):

v24.22.1
11.19.1

The first line is Node.js; the course needs 24.15.0 or later on the 24 line. Version 22.22.2 or later, or 26, also works. The second line is npm, which comes with Node.js; any version that came with a supported Node.js is fine.

What you seeWhat it meansWhat to do
Two version numbers, Node.js 24.15 or laterReadyGo to Step 2
command not found, or "not recognized as the name of a cmdlet"Node.js is not installed, or the terminal cannot find itInstall it, then open a new terminal
A version below 24.15 (for example v20.11.0 or v24.3.0)Too old for the course's toolsInstall a current 24 release

To install, use the official download page at nodejs.org and choose the LTS (long-term support) release, which is the 24 line. The installer for your system adds both node and npm. If you already use a Node.js version manager such as nvm, install the latest 24 release through it instead. After installing, open a new terminal window so it picks up the change, and run the two version commands again.

Why 24.15? One of the testing tools added later in the course declares that it needs at least that version. Starting with a version that satisfies every tool avoids a confusing failure halfway through.

Step 2: Create the Practice Folder

Every practical lesson works inside one folder, so nothing touches your other files. Create it in your home folder and move into it:

cd ~
mkdir react-foundations-practice
cd react-foundations-practice
pwd

~ means your home folder in all three terminals. pwd should print a path ending in react-foundations-practice. If mkdir says the folder already exists, that is fine: just cd into it. You can put the folder somewhere else if you prefer; the course only ever refers to it by name.

Step 3: Create the Project

Run this from inside react-foundations-practice:

npm create vite@9.3.1 first-app -- --template react --no-eslint --no-immediate

Each part has a job:

  • npm create vite@9.3.1 downloads and runs Vite's project generator, create-vite, at the exact version this course was checked with. Without @9.3.1 you would get the newest version, whose files may differ from the lesson.
  • first-app is the name of the folder it creates.
  • -- tells npm that the remaining options are for create-vite, not npm.
  • --template react chooses the plain JavaScript React template.
  • --no-eslint keeps the template's default code checker; a later lesson sets up the checker the course uses.
  • --no-immediate stops the generator from installing and starting the project for you, so you can do and see each step yourself.

The first time, npm asks before downloading the generator:

Need to install the following packages:
create-vite@9.3.1
Ok to proceed? (y)

Press y, then Enter. When it finishes, it prints the next steps. Their form, from a checked run (the folder path will show your own location):

create-vite v9.3.1

│
◇  Scaffolding project in /path/to/react-foundations-practice/first-app...
│
└  Done. Now run:

  cd first-app
  npm install
  npm run dev

Step 4: Install the Packages

Move into the new project and install what it depends on:

cd first-app
npm install

npm install reads package.json, the file that lists the project's dependencies and commands, and downloads every package it needs, including the packages those packages need. It creates two things:

  • node_modules/, a folder holding the downloaded packages. It is large (about 56 MB for this template) and you never edit it; it can always be recreated with npm install.
  • package-lock.json, a record of the exact version of every package that was installed, so the same versions can be installed again later.

The command prints a summary such as added 24 packages in 20s; the count and time vary. Lines starting npm warn are warnings, not failures. Lines starting npm error, and a non-zero exit, mean the install failed; see When It Does Not Work.

Step 5: Start the Dev Server

npm run dev

npm run dev runs the command stored under "dev" in package.json, which is vite. Illustrative output from a checked run (the timing varies):

  VITE v8.3.5  ready in 220 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  • Local is the address to open. localhost means your own computer, and 5173 is the port: the "door number" the server listens on.
  • Network: use --host to expose tells you the server is reachable only from your own computer. That is the safe default, and the course never changes it.

Open the Local address in your browser. You should see the template's page, with the heading Get started and a Count is 0 button you can click.

Step 6: Change It and Watch It Update

Open the first-app folder in your code editor and find src/App.jsx. Near the top of what the component returns is this line:

// Illustrative fragment: the heading in the template's src/App.jsx
<h1>Get started</h1>

Change the text to Hello, React and save the file. Without refreshing, the browser page changes within a moment. Vite noticed the saved file and sent the updated module to the page. The template's own text calls this HMR, hot module replacement. You do not need to restart the server or refresh the page after normal edits.

Click the counter a few times, then make another edit. The count is normally kept, because the update swaps in the new code without reloading the page. That is a development convenience, not something your app does for its users; a real page refresh starts the counter from 0 again.

Step 7: Stop the Server

Click in the terminal and press Ctrl+C. The vite process stops and the prompt comes back. Some Windows terminals ask you to confirm stopping a batch job; answer Y.

Refresh the browser page now. It shows the browser's own "unable to connect" or "site can't be reached" message, because nothing is listening on port 5173 any more. The page was never a file you opened. It was served by the dev server, and it disappears when the server stops. To see it again, run npm run dev again from inside first-app.

What Success Looks Like

CheckExpected
node --version24.15.0 or later (or 22.22.2+, or 26)
pwd before creating the projectEnds in react-foundations-practice
ls inside first-app after installingShows index.html, package.json, package-lock.json, node_modules, public, src, vite.config.js (and README.md)
The Local address in the browserThe template page, with your new heading
Saving src/App.jsxThe page updates without a manual refresh
Ctrl+C, then refreshing the pageThe browser cannot connect

When It Does Not Work

The generator says the folder is not empty. If first-app already exists and contains files, create-vite asks:

Target directory "first-app" is not empty. Please choose how to proceed:

Choose Cancel operation. The other choices either delete the folder's existing files or mix the template with them. Then either cd into the existing project and continue from Step 4, or run the command again with another name.

Install warnings mentioning EBADENGINE. npm checked the Node.js versions the packages declare and your Node.js is outside them. Check node --version; install a supported version (Step 1), then run npm install again.

npm error with a network message (for example ETIMEDOUT or ENOTFOUND). npm could not reach the registry. Check your connection, including any company proxy or VPN, and run the command again. Re-running npm install is safe: it completes whatever is missing.

npm run dev says it could not read package.json. You are not in the project folder. Run from the practice folder, the error begins like this (observed; the path shows your own location):

npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/path/to/react-foundations-practice/package.json'

ENOENT means "no such file". pwd should end in first-app; if it ends in react-foundations-practice, run cd first-app and try again.

The port is different. If something else is already using port 5173, Vite tries the next one and tells you:

Port 5173 is in use, trying another one...

  VITE v8.3.5  ready in 508 ms

  ➜  Local:   http://localhost:5174/

This is usually an earlier dev server you forgot to stop, in another terminal window. Always open the address Vite prints. Stop the old server if you do not need it.

The page is blank. Look in the browser's developer console (F12, or Cmd+Option+I on macOS) for a red error, and in the terminal running Vite. A syntax mistake in a file you edited is the usual cause. Vite shows an error overlay on the page that names the file and line. Fix the file and save; the page recovers.

Your Turn: Two Servers at Once

Leave one dev server running. Open a second terminal window, cd into react-foundations-practice/first-app, and run npm run dev again.

Predict before you look: what address will the second server print, and what will you see at each address?

Answer

The second server prints Port 5173 is in use, trying another one... and starts on http://localhost:5174/. Both addresses show the same page, because both servers serve the same project folder. Edit the heading again and both pages update. Stop both servers with Ctrl+C in each terminal before moving on. A forgotten second server is the most common reason for an unexpected port later in the course.

Check Your Understanding

With the dev server stopped, you refresh the browser tab that showed your app. What do you see, and why? What single command brings the page back, and in which folder must you run it?

Answer and Reasoning

The browser shows its own "unable to connect" message. The page was being served by the dev server process, not opened from a file, so once that process stops nothing answers on that port. Run npm run dev from inside the first-app folder, where the project's package.json defines the dev command, then open the address it prints.

Reset and Clean Up

Stop any running dev servers with Ctrl+C. Keep first-app: the next lesson explores its files, and you will use it again in Components and JSX.

If something went wrong and you want to start again, stop the server, move up to the practice folder and delete only first-app:

cd ~/react-foundations-practice
pwd

Check that pwd ends in react-foundations-practice, then delete the first-app folder there using your file manager (Finder, File Explorer or your Linux file manager), and repeat from Step 3. Deleting first-app removes nothing else.

References

30 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy