Sub topic 9
Checking Node.js and npm
This chapter assumes you can use a terminal and know basic JavaScript, including ES modules. You will confirm that Node.js and npm are installed and recent enough to run Vite.
Why Vite needs Node.js
Vite is a tool written in JavaScript. It does not run in the browser. It runs on your computer, so it needs a JavaScript runtime outside the browser. That runtime is Node.js.
npm is the package manager that comes with Node.js. It downloads libraries such as React and Vite into a node_modules folder. It also runs the scripts listed in package.json, such as npm run dev.
Check your versions
Open a terminal and run these two commands.
node --version
npm --versionEach command prints a version number, for example v22.12.0 for Node.js and 10.9.0 for npm. Your numbers will differ.
Recent Vite releases require a current Node.js version. Vite's documentation lists Node.js 20.19+ and 22.12+ as supported. Check the Vite docs if your version is close to these numbers, because the requirement changes between releases. An even-numbered release line is a long-term support (LTS) release, and LTS is the safest choice.
| Result | Meaning | What to do |
|---|---|---|
| Version at or above the requirement | Ready to go | Continue to the next chapter |
| Older version | Vite may refuse to start or fail with syntax errors | Upgrade Node.js |
| `command not found` | Node.js is not installed or not on your PATH | Install Node.js |
Install or upgrade Node.js
You have two common options.
- Download the LTS installer from the official Node.js website. This is the simplest option.
- Use a version manager such as nvm, fnm, or Volta. These let you keep several Node.js versions and switch between them per project.
A version manager helps once you work on more than one project. An old project may need an older Node.js version while a new Vite project needs a newer one.
Here is an example with nvm.
nvm install --lts
nvm use --lts
node --versionAfter installing, close and reopen your terminal, then run the version commands again. A terminal that was open during installation often keeps the old PATH.
Common errors
node: command not found: Node.js is missing, or the terminal has not picked up the new PATH. Restart the terminal.- Version looks right in one terminal but wrong in another: A version manager may apply only to the current shell. Run
node --versionin the terminal where you will run Vite. - Permission errors when installing packages: Do not fix these with
sudo npm. Install Node.js in a way that keeps it in your user directory, such as a version manager.
Exercise
You run node --version and see command not found, but you installed Node.js a minute ago. What is the most likely cause, and what should you try first?
Show answer
The terminal was open before the install and has not loaded the updated PATH. Close and reopen the terminal, then run node --version again.