Skip to content

NPM

NPM (Node Package Manager) is the tool we use to download and manage the libraries our projects depend on. Instead of hunting down every library by hand, NPM reads a list of what the project needs (a file called package.json) and installs all of it for you with one command.

NPM doesn’t get installed on its own. It comes bundled with Node.js, which is the program that runs JavaScript outside of a web browser. So to get NPM, we install Node.js.

Go to the Node.js download page and download the Windows Installer (.msi).

You’ll see two kinds of versions offered:

  • LTS (Long Term Support): the stable version. Pick this one.
  • Current: the newest features, but less tested.

Make sure the architecture matches your computer. For almost every modern Windows machine, that’s x64. If you’re not sure, press your Windows key, search for About your PC, and look at the System type line.

Once it has been downloaded, open the .msi file from your Downloads folder and follow the prompts:

  1. Click Next on the welcome screen.
  2. Accept the license agreement and click Next.
  3. Leave the install location as the default and click Next.
  4. On the Custom Setup screen, leave everything as it is. Make sure npm package manager and Add to PATH are both included (they are by default). Click Next.
  5. On the Tools for Native Modules screen, leave the box unchecked and click Next. We don’t need these, and they take a long time to install.
  6. Click Install. If Windows asks whether you want to allow the app to make changes to your device, click Yes.
  7. Click Finish once it’s done.

If you had a Command Prompt window open from before, close it and open a new one. Command Prompt only picks up newly installed programs when it starts.

Open the command line by pressing your Windows key and searching for cmd, then run the application called Command Prompt.

First, check that Node.js is installed:

Get Node version
node --version

It should print out a version number, something like v22.20.0.

Next, check that NPM is installed:

Get NPM version
npm --version

It should print out another version number, something like 10.9.3. The exact numbers don’t matter, as long as you get a number and not an error.

Seeing a version number means it’s installed, but let’s make sure it actually works.

Node.js can run JavaScript right from the command line:

Run JavaScript with Node
node -e "console.log('Hello from Node!')"

It should print Hello from Node!.

Let’s create a throwaway project and install a package into it. First, make a new folder and move into it:

Make a test folder
mkdir npm-test
cd npm-test

Create a new project. The -y just says “yes” to all the default settings:

Create a new project
npm init -y

This creates a package.json file, which is the list of everything your project depends on. It will print the contents of that file to the screen.

Now install a package. We’ll use cowsay, a small (and very important) package that makes a cow say things:

Install a package
npm install cowsay

When it finishes, you’ll see a message like added 41 packages. You’ll also notice a new node_modules folder in your project. That’s where NPM puts all the downloaded code.

Finally, run it:

Run the package
npx cowsay "I installed NPM!"

npx runs a package that’s installed in your project. If a cow shows up saying your message, everything is working.

__________________
< I installed NPM! >
------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

You can delete the npm-test folder once you’re done. We won’t need it again.

'node' is not recognized as an internal or external command

Section titled “'node' is not recognized as an internal or external command”

Windows can’t find Node.js yet. Close every Command Prompt window and open a new one. If that doesn’t fix it, restart your computer. If it still doesn’t work, run the installer again and make sure Add to PATH is included on the Custom Setup screen.

npm.ps1 cannot be loaded because running scripts is disabled on this system

Section titled “npm.ps1 cannot be loaded because running scripts is disabled on this system”

This only happens in PowerShell (including the terminal inside VS Code), not in Command Prompt. Windows blocks PowerShell scripts by default. To allow them for your user account, open PowerShell and run:

Allow PowerShell scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Type Y and press Enter if it asks you to confirm. You can read more about what this does in Microsoft’s documentation on execution policies.