Skip to main content
npm-start-not-working

npm command not working?

This tutorial helps to solve the npm command not found issue. We’ll discuss a way to solve this issue. The npm install command is used for installing JavaScript packages on your local computer.

This error will occur whenever you are developing web projects, you may see issues that cause the npm install command to fail to install the dependency.

Checkout Other Nodejs tutorials:

You need to see the error message generated in the terminal.

$ npm install -g axios
zsh: command not found: npm

Node.js?

Node.js is a runtime environment that allows developers to run JavaScript on the server side. It is built on the V8 JavaScript runtime.

npm (Node Package Manager)?

npm is the default package manager for Node.js, enabling developers to install, share, and manage dependencies in their projects.

PATH variables?

The PATH environment variable is a list of directories specifying where your computer should look for a program to run from the Terminal.

Your computer will search through all of the folders listed under PATH when you run the npm command from the terminal in order to locate the npm executable file and deliver your commands to it.

npm: command not found

To run the npm install command, you need to have npm installed on your computer.

Your computer will display the command not found error if the npm executable file cannot be located.

Node.js Not Installed

Initially, you must ensure that npm is set up on your PC. The npm is bundled with Node.js server, So you can download from the nodejs.org website.

install it and open the terminal and run the npm -v command.

node -v

It gives me the version as

16.11.0

Check npm Installation?

You can also need to check npm is installed or not:

npm -v

How To Set PATH Variables

The system’s PATH environment variable might not include the path to npm. Update your PATH variable to include the location where npm is installed. my installation path is:

C:\Program Files\nodejs

First, We’ll verify Path variables values, Open your terminal and run the following command to check if the paths are correctly set:

echo $PATH

If the installation path is not present, you’ll need to add the folder where the npm executable file is located back to the PATH variable OR you can set the PATH variable by using Windows graphical UI.

Update the location to the Windows PATH environment variable using the Command Prompt as follows:

SET PATH=C:\Program Files\nodejs;%PATH%

package.json file is not found

Sometimes, package.json is not found or not into the project location.

How to Create Package.json file

The below command is used to create package.json file.

npm init

The above command will create package.json file (you will be asked for some data to fill it). Then npm intall [--save|saveDev] will work properly.

install a package using npm command line

To install dependencies node looks for a file in the root of the project called package.json, where you have the list of all the dependencies needed for the project. its content looks like something like this:

sounds like you are missing package.json in the root of your project.

to install a dependency you usually run a command like

npm install axios --save-dev

This also automatically updates your package.json

In order for npm install to work, you need to be in the same directory as your package.json file. npm install then looks at the package.json and installs all the dependencies there.

Conclusion

We have tried different ways to solve errors such as “npm command not found issue“. Please make sure that you have installed node with npm, PATH environment variable. However, by understanding the situation and using the right solutions can lead to a resolution.

Leave a Reply

Your email address will not be published. Required fields are marked *