"npm" is not recognized as an internal or external command, operating program or batch file

I am completely new to nodejs. I am trying to get nodejs to work on my Windows 2008 computer to install Karma, which I would use for TDDing my AngularJs code. I have taken the following steps so far

  1. Installation using Chocolatey ==> npm is not recognized
  2. Installation using a 64-bit nodejs installer from nodejs.org ==> npm is not recognized
  3. At this point in the run, where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing
  4. I found out that nodejs is installed in C:\Program Files\nodejs . Opening a command prompt in this directory makes npm work fine.
  5. So I added C:\Program Files\nodejs to PATH just to get the same error again that npm is not recognized
  6. One of the github issues in the nodejs repository is that I need to restart my computer and this will fix it. But it has not helped so far
  7. I see the Node.js icon in Start → Programms which brings me to the nodejs console, but I'm not sure what to do with it.

Did I miss any important step in the process?

edit

I realized that if I open Nodejs Command Prompt from program files, npm will be recognized. How do I get it to work on a regular command line?

edit

After node I ran into a similar problem with another application. I posted this question on the superuser and, as rightly pointed out in the accepted answer, I had an additional quote in my PATH that caused problems with all the paths added after the quote. I have a feeling that some Chocolatey installation adds this alarming quote, but I'm just not sure which one.

+142
windows
Jan 08 '14 at 10:18
source share
22 answers

Just add:

 ;C:\Program Files\nodejs\ 

To the end of the variable Path in the section "Custom variable of environment variables in the system properties.

After that, re-run your command prompt and enter

 npm 

That should work.

+275
Feb 21 '14 at 1:14
source share

Do not forget to restart your computer after installing node! It bothered me.

+83
Mar 13 '14 at 9:48
source share

To clarify Brenot's answer ... For Windows 7, these steps helped me:

  1. Open the control panel (click the "Start" button, then click "Control Panel")
  2. Click User Accounts
  3. Click Change My Environment Variables
  4. Select PATH and click the Change ... button.
  5. At the end of the variable value add ;C:\Program Files\nodejs
  6. Click OK in the Edit User Variable window, then click OK in the Environment Variables window.
  7. Launch a command prompt window (click Start, then type cmd in the search and press Enter)
  8. At the command prompt ( C:\> ), type npm and press enter; You should now see the help text ( Usage: npm <command> , etc.) instead of "npm not recognized ..."

Now you can start using npm !

+25
Aug 05 '14 at 20:50
source share

For Windows users: a picture tells a thousand words enter image description here

Refrence: " npm is not recognized as an internal or external command

+14
Nov 28 '17 at 4:27
source share

Remember to run cmd as admin.

+13
Jun 12 '14 at 19:45
source share

I had the same problem described by Ashu , but in addition to this, the PATH entry for nodejs was completed with a backslash:

 C:\Program Files\nodejs\ 

I also had to remove this final backslash in order for it to work.

+10
Jul 08 '14 at 3:56
source share

I ran into the same problem and noticed that after installing node.js, a new path entry appeared in the user variable section for PATH with the value → c: \ User \\ AppData \ Roaming \ npm. Also, the Path entry in the system variable is added using → C: \ Program Files \ nodejs. Now, since the user variable has a preference over the system, you have two options to fix this. Either remove the path from the user variable, or correct the correct path (C: \ Program Files \ nodejs). Reboot the CMD and it should work.

+8
Jun 20 '14 at 5:15
source share

If you get this error through a service account, such as the Visual Studio TFS Build Manager service or any other background service, make sure you restart the service after installing npm, as new PATH settings will not be received by those who are already running processes. I was getting the same error through my build service, but I installed and ran npm in the console.

+5
Jan 22 '16 at 21:08
source share

Had the same problem on Windows 8.1 64 bit.
It turns out I get this problem if I run cmd by typing it in the path bar at the top of the folder window
or
when I shift the right click in the folder window, and then open the command line from the list. <ears>
When I run cmd using Run or Just from the cmd.exe executable, it works.

+4
Jun 27 '15 at 19:06
source share

You may have already received the answer, but this may help others, as I recently ran into the same problem, and here is what I did:

  1. The path to the powershell file is provided. For me, the path was C: \ Windows \ System32 \ WindowsPowerShell \ v1.0
  2. Then I opened a command prompt with administrator privileges and copied this

    @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new net.webclient object) .DownloadString (' https://chocolatey.org/install.ps1 '))" && SET PATH =% PATH%;% ALLUSERSPROFILE% \ chocolate \ bin

at the cmd command prompt.

  1. Next choco install nodejs
  2. Reboot and everything worked fine. Try opening cmd without administrator privileges and running npm -v Cheers.
+3
Dec 21 '14 at 16:51
source share

I installed nodejs after this AngularJS tutorial . The npm command worked when I open a new cmd window, but not in the current one.
So, the fix was to close and open a new cmd window .

+2
Dec 05 '14 at 11:21
source share

I ran into this problem the other day on my Windows 7 machine. The problem is not in my way, but I had to use hidden slashes instead of backslashes like:

 "scripts": { "script": ".\\bin\\script.sh" } 
+2
Sep 08 '15 at 12:25
source share

If the package is successfully installed and the message " npm" is still displayed , it is not recognized as an internal or external command, operating program, or batch file. "

  • Click the Windows start button.
  • Search for " ALL APPS ", you will see Node.js and Node.js Command Prompt.
  • You can run the Node.js command prompt as an administrator, and shortly after it starts, the message "Your environment has been configured to use Node.js 6.3.0 (x64) and npm" appears.

and then it works from there ...

+2
Jul 18 '16 at 23:01
source share

I ran into this problem. Turns out Windows doesn't use single quotes on the command line. The culprit was one of my npm scripts. I changed single quotes to double quotes:

 'npm -s run sass-build' 

to

 \"npm -s run sass-build\" 
+2
Jan 04 '17 at 4:42 on
source share

I installed Node.js and when trying to install Ionic and cordova using this piece of code:

npm install -g cordova ionic

I encountered the above error. I added "C: \ Program Files \ nodejs" to the "PATH" environment variable. But so far, this problem has not been overcome. It turned out that my PATH variable was longer than 2048 characters, so I could not add the Nodejs path to it. I had to remove the path of another program and add the Nodejs path. Close and reopen the cmd prompt and try installing Ionic again. It worked for me.

+1
May 17 '16 at 21:24
source share

I am updating this thread with a new answer because I found a solution to my miserable situation after at least a week ...

For those who still experience the error, even if they have their path value set correctly, check the pathext variable for the value (default value in Windows 7 +) :. COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS; .JSE; .wsf; .wsh; .msc

The mine had to establish only: .BAT and its change solved the problem. I wonder why no one raised this ...

Hope this helps!

+1
May 04 '17 at 9:59 p.m.
source share

for me adding path to PATH didn't help. c:\Program Files\nodejs\nodevars.bat this run c:\Program Files\nodejs\nodevars.bat , it will do all the work for you

+1
Sep 10 '18 at 11:11
source share

In my case, while testing through Mocha, I tried everything just to understand that I need to remove single quotes around the test script tag in package.json .

I am running a mocha test, on all *.test.js files as can be seen below:

package.json

Before:

  "scripts": { "test": "mocha server/**/*.test.js", "test-watch": "nodemon --exec 'npm run test'" } 

After (removing single quotes - npm run test):

  "scripts": { "test": "mocha server/**/*.test.js", "test-watch": "nodemon --exec npm run test" } 

Worked for me, in case anyone else gets stuck on this.

+1
Oct 08 '18 at 13:20
source share

Just download and install Node.js from here https://nodejs.org/en/

If you run the downloaded file and install it, they will be automatically configured for your system

You no longer need any other configurations, now you can use the npm command anywhere




If Nodejs is successfully installed and still displays a message like this:

"npm" is not recognized as an internal or external command, a running program, or a batch file.

For Windows users, follow these steps:

  1. Go to my computer properties
  2. Click Advanced System Setting in the left pane of the window.
  3. You now have a System Properties window. Click Advanced
  4. Then click the Environment Variable button.
  5. Now you have the window of the environment variable: from the system variable, select the path
  6. Click Edit
  7. At the end of the variable value add ;C:\Program Files\nodejs\

    Note If you installed nodejs on other drives, proceed accordingly.

  8. Click Ok all open dialog box

Very important note : "Close the command line and restart again" (this is very important because if you did not restart the command line, the changes will not be reflected.)

Now you can use the npm command anywhere

+1
Apr 05 '19 at 6:39
source share

For windows8, right click my pc properties then click environment variables user variable or system variables → new → put the variable name and path: for example C:\Program Files\nodejs Then ok now open cmd and type npm , it will work

0
Jun 03 '15 at 17:46
source share

go to Node.js download and install it; close and then open the Visual Studio code for Visual Studio again,
now everything will work, at least on a windows machine.

to access the embedded code in Visual Studio: Terminal
in the top menu, click View> Integrated Terminal

start typing the necessary commands related to npm or other operations Command line .


from a Microsoft Windows user experience;
these activities are brain processing consuming;
be aware off to keep it simple for a Windows Forms productivity;
these are the scheme of Open Source organizations - seem lazy by IDE workflow value;

0
Jun 04 '17 at 0:46
source share

We need to install nodejs, and we don’t need to do anything else, and then just use the command line and change the directory to the project where you want to install npm, and then use the npm install command. It worked for me.

0
Nov 22 '17 at 6:07
source share



All Articles