Fixing 'npm' is not recognized error

The npm (Node Package Manager) application is a package manager for the JavaScript language that allows you to install JavaScript libraries or modules by using the npm install command.

npm is bundled together with NodeJS, so each time you install a specific version of NodeJS on your local computer, you will also have a specific version of npm bundled with it.

You can check the currently installed npm version using the npm --version command:

> npm --version

But sometimes, you may encounter the npm is not recognized error as shown below:

> npm --version
'npm' is not recognized as an internal or external command,
operable program or batch file.

The error above happens when the Windows operating system doesn’t know what to do with the npm command.

To fix the error, you need to make sure that the Node executable file is available under your PATH setting.

Note: NodeJS should have added the executable location to your PATH variable during installation process, but sometimes it may fail to do so.

You can add new entry to the Windows PATH environment variable using the Command Prompt as follows:

> SET PATH=C:\Program Files\Nodejs;%PATH%
> npm

Or you can set the PATH variable by using Windows graphical UI.

The following steps will help you to fix the error from Windows interface.

Fixing npm is not recognized error on Windows OS

First, Go to My Computer or This PC for Windows 10. Right-click on empty space and open the Properties window:

Click Advanced system settings from the left bar of the Properties window:

Now you’re in the System Properties window. Click the Environment Variables... button:

Now you’re in the Environment Variables window. Select the Path variable from either the User Variables or System Variables table and click on the Edit... button:

At the end of the variable values, add C:\Program Files\nodejs as a new entry to your Path variable:

If you installed NodeJS on another location, then you need to change the entry to your custom location. Remember to always enter the absolute path from the drive letter to your NodeJS program folder.

Once done, click OK and open a new Terminal or Command Line window. If you’re calling npm from the VSCode terminal, you need to restart VSCode first before trying again.

The npm is not recognized error should be fixed and you should be able to check this using the npm --version command:

> npm --version
7.15.1

If you still get the error, then try restarting your computer first. The error should be gone after you restart.

Now you should be able to install any npm package to your local computer with npm install command. Great job on fixing the error!

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.