To set up Node.js and npm for React development, install the current LTS (long-term support) release of Node.js, which includes npm, then confirm both with node --version and npm --version. After that you can create a React project with a single npm command and start its development server. Node.js is not part of your finished React app in the browser; it is the tool that installs packages and runs your build.
This article covers installing Node, checking the install, understanding package.json, and running the common npm commands you will use regularly.
React code is written with modern syntax (JSX, modules, TypeScript) that browsers do not run directly. A build tool turns it into plain JavaScript. These tools are written in JavaScript and run on Node.js, a runtime that executes JavaScript outside the browser.
npm (Node Package Manager) comes with Node.js. It downloads libraries such as react and react-dom from the npm registry into a node_modules folder, and it runs project scripts like npm run dev.
| Tool | Role |
|---|---|
| Node.js | Runs JavaScript tools on your computer |
| npm | Installs packages and runs scripts |
package.json | Lists your project's dependencies and scripts |
node_modules | Folder of installed packages (never edit or commit it) |
Choose one of these ways. Pick an LTS release, because LTS versions get fixes for a long period and are what most tools support.
nvm (macOS and Linux), nvm-windows, fnm or volta. A version manager lets you switch Node versions per project, which is useful once you work on several projects.brew install node) or your Linux distribution's repository, though distribution packages are often behind.With nvm, for example:
Build tools state a minimum Node version. Vite, for example, drops old Node releases over time, so check the Vite documentation if the installer complains about your version.
Open a new terminal window so the updated path is loaded, then run:
Your numbers will differ. If you see "command not found", the install did not finish or the terminal was opened before installing. Close it, open a new one and try again.
You can also test Node quickly:
With Node ready, create a project using Vite (covered in more detail in a related article):
npm create vite@latest downloads and runs the project generator. npm install reads package.json and installs the dependencies. npm run dev starts a development server and prints a local address, usually http://localhost:5173. Open it in your browser to see the starter app, and edit the source to see it update instantly.
package.json is the file npm reads. A trimmed example from a Vite React project:
The scripts section defines what npm run <name> does. The ^ before a version allows compatible minor and patch updates. Exact versions in your project may be newer.
| Command | What it does |
|---|---|
npm install | Installs everything in package.json |
npm install <package> | Adds a package and saves it as a dependency |
npm install -D <package> | Adds a development-only dependency |
npm run dev | Starts the development server |
npm run build | Creates the optimised production build |
npm uninstall <package> | Removes a package |
The package manager also writes a lock file, package-lock.json. Commit it so everyone installs identical versions, but never commit node_modules.
sudo npm install -g.node --version and switch with your version manager.--port.You may also meet alternatives such as pnpm, Yarn and Bun. They install the same packages, and you can use them later, but npm is enough here.
No. The built app is static HTML, CSS and JavaScript that any web server can serve. Node is needed to develop and build it, and for server rendering.
Install the current LTS release unless a project says otherwise. A version manager lets you change it per project.
npm installs and manages packages. npx runs a package's command without installing it permanently. npm create is a shortcut that runs a project generator.
Usually not. Install them per project as dependencies so each project has its own versions.
Install an LTS version of Node.js, verify it with node --version and npm --version, and use npm to create and run your React project. Learn the role of package.json, the dev and build scripts, and keep node_modules out of version control. A version manager makes switching Node versions painless as your projects grow.