For those who are using JavaScript to develop a web project for the first time, installing Node.js and npm (Node’s default package manager) is an essential first step.
These tools are required to run and build JavaScript/TypeScript projects, including Astro-based websites.
Step-by-step Guide to Install Node.js and npm Globally:#
Option 1: Install via Node.js Official Website#
- Visit: https://nodejs.org
- Download the LTS version (Long Term Support), which is the most stable for development.
- Install it like a regular app (on macOS, Windows, or Linux).
After installation, open your terminal (or WebStorm’s built-in terminal) and check:
node -v # shows Node.js versionnpm -v # shows npm versionYou should see something like:
v20.11.110.2.4If these show up, you’re ready to use JavaScript tools like npm, pnpm, or yarn.
# Then install pnpm globally
npm install -g pnpmOption 2: Use nvm to Manage Multiple Node.js Versions (Recommended for Developers)#
If you’d like more flexibility (for example, different projects require different Node versions), use nvm (Node Version Manager):
# Install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Restart terminal, then run:nvm install --ltsnvm use --ltsThen check:
node -vnpm -vThis method is especially useful for managing environments, similar to using
pyenvorcondain Python.
After Node.js and npm are installed, you can install pnpm globally if your project uses it:
npm install -g pnpmThen run:
pnpm installpnpm devYour Astro/JavaScript project should now be up and running.
Recap#
For first-time WebStorm or JavaScript users:
- Yes, you do need to install Node.js + npm globally;
- Tools like
nvmmake managing Node.js versions cleaner and safer; - Once installed,
pnpm,npm, andnode_moduleshandle everything inside the project — no need for a separate “virtual environment” like in Python.
Common Errors When Installing Node.js and pnpm (And How to Fix Them)#
When setting up a Node.js-based project (e.g. Astro) for the first time, it’s common to encounter installation-related errors. This section explains several typical issues and how to resolve them.
Error 1: command not found: pnpm#
Cause: pnpm is not installed globally on the system.
How to fix:
Install pnpm using npm:
npm install -g pnpmIf pnpm -v shows a version number afterwards, you’re good to go.
Error 2: EEXIST: file already exists#
Error message example:
npm ERR! EEXIST: file already exists, symlink '/usr/local/bin/pnpx'Cause: There’s a leftover or conflicting file at /usr/local/bin/pnpx, which blocks the installation of pnpm.
Solutions:
✅ Option 1: Force the installation (quick fix)
npm install -g pnpm --force✅ Option 2: Clean the conflicting file (recommended)
sudo rm /usr/local/bin/pnpxnpm install -g pnpmAfter that, verify installation:
pnpm -vError 3: astro: command not found#
Cause: You are trying to run the project with pnpm dev before installing dependencies, so the astro command is missing.
Solution:
Install all dependencies first:
pnpm installThen start the development server:
pnpm devThis should launch your Astro project on http://localhost:4321/.
Extra Tip: How to Confirm Your Setup is Working#
After installation, check the following versions:
node -v # should return something like v20.11.1npm -v # e.g. 10.2.4pnpm -v # e.g. 9.1.2If all three commands work, you’re ready to develop!