The error message “npm: The term npm is not recognized as the name of a cmdlet, function, script file, or operable program” usually occurs for two main reasons:
For older versions of Windows, you might see an error like: “‘npm’ is not recognized as an internal or external command, operable program, or batch file.”
To resolve this issue on Windows, follow these steps:
If Node.js isn’t installed, you’ll need to download and install it. This will also install npm (Node Package Manager) as part of the process.
First, open the Node.js official website and download the LTS installer as shown below.
After downloading, Install Node.js and npm using the installer.
Once the installer is done, let’s try checking if the error is resolved or not by verifying the npm version on cmd/PowerShell.
npm --version
If all steps are done correctly, then this command should return the version of the npm installed in our system.
If it still returns the “‘npm’ is not recognized as an internal or external command, operable program, or batch file” error, then we will move forward to Solution 2.
In case you’ve already installed Node.js but continue to encounter this error, the next step involves modifying the npm path within the Windows environment variables. Adding the location of npm into your system’s Path variable guarantees the recognition of this tool through the command line interface. This issue predominantly emerges when the system is unable to pinpoint the installation location of npm. We will rectify this by appending npm to the path. Follow these steps to successfully complete the process:
1. Click on your search icon beside the windows icon and type “Environment Variables”
2. Click on the first option “Edit the system Environment Variables”. A System Properties window will open. Click on “Environment Variables”
3. Select Path and click on “Edit”
4. Click “New” and add the location of the NodeJS installation.
To discover the installation location of Node.js, navigate to the installation directory for Node.js. Begin by accessing your C Drive, then locate the ‘Program Files’ folder. Inside this folder, you will come across the ‘nodejs’ folder. Open this folder and copy its path. This is how my nodejs folder looks:
5. You have to copy this path and add it as an environment variable by pasting it in the edit environment variable dialogue box:
Your “Edit environment variables” dialogue box will look something like this:
Now, we will also add the ‘npm’ directory. The ‘npm’ directory is most likely located under %USERPROFILE%\AppData\Roaming\ npm, which is the same as C:\Users\YOUR_USER\AppData\Roaming\npm.
These are the environment variables in their final configuration.
Now, click “Ok” to close all the dialogue boxes, and you are almost done!
Make sure you restart your terminal to apply the changes. Now try to run an npm command, and it should work without any errors.
npm --version