
This error means that your system doesn’t recognize the npm command, usually because Node.js and npm are not installed correctly, or the path to npm isn’t set up properly in your environment variables. Let’s explore how to resolve this issue step by step.
npm : The term ‘npm’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Step 1: Verify Installation of Node.js and npm
First, check if Node.js and npm are already installed on your system. Open a terminal or command prompt and type:
node -v
npm -v
If these commands return version numbers, Node.js and npm are installed. If you see an error message, you’ll need to install them.
Step 2: Install Node.js and npm
To install Node.js and npm, follow these steps:
Download Node.js: Visit the official Node.js website and download the installer for your operating system. The npm package manager is included with the Node.js installer.
Run the Installer: Follow the installation instructions. Ensure that the option to install npm is checked.
Step 3: Update System Environment Variables (Windows)
If Node.js and npm are installed but not recognized, you might need to add the installation directory to your system’s PATH environment variable:
Open Environment Variables Settings:
Right-click on ‘This PC’ or ‘My Computer’ on the desktop or in File Explorer.
Select ‘Properties’.
Click on ‘Advanced system settings’.
Click on the ‘Environment Variables’ button.
Edit the PATH Variable:
In the ‘System variables’ section, scroll down and find the ‘Path’ variable, then click ‘Edit’.
Add the path to the directory where Node.js is installed (e.g., C:\Program Files\nodejs).
Apply and Restart:
Click ‘OK’ to apply the changes.
Close any open command prompts or terminals and reopen them for the changes to take effect.
Step 4: Verify Installation Again
After installation and updating the PATH variable, verify the installation by running:
node -v
npm -v
Step 5: Run npm Install
Once Node.js and npm are properly installed and recognized, navigate to your project directory and run:
npm install
This command installs all the dependencies listed in your package.json file.