391

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

  1. Install using Chocolatey ==> npm is not recognised
  2. Install using 64-bit nodejs installer from nodejs.org ==> npm is not recognised
  3. At this stage, running where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing in it
  4. I figure 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 only to get the same error again that npm is not recognized
  6. One of the github issues on nodejs repository says that I need to restart the machine and it would fix. But that has not helped so far
  7. I do see a Node.js icon in my Start -> Programms mennu which takes me to nodejs console but not sure what to do with that.

Have I missed any important step in the process?

Edit

I figured out that if I open "Nodejs command prompt" from program files, then npm is recognized. How do I make it work on a normal command prompt?

Edit

After node I started facing a similar problem with another application. I posted this question on superuser and as rightly pointed out by the accepted answer, I had an additional quote in my PATH which was causing issues with all the paths added after the quote. I have a feeling that some Chocolatey install adds this troubling quote but I am just not sure which one.

7
  • 18
    After adding to the PATH, did you restart the command line? PATH is only loaded when initializing new command line sessions. Jan 8, 2014 at 10:30
  • 2
    Yes Davin, I have restarted command line several time now
    – Suhas
    Jan 8, 2014 at 10:52
  • I've got "C:\Program Files\nodejs\" in my system PATH and everything working on Windows 7. Jan 8, 2014 at 12:00
  • 7
    Can you open a new command prompt and type PATH (hit <enter>) and double-check that you see "C:\Program Files\nodejs\" in there? Jan 8, 2014 at 12:02
  • 2
    Yes, I do have C:\Program Files\nodejs in PATH
    – Suhas
    Jan 8, 2014 at 12:54

43 Answers 43

555

Just add:

;C:\Program Files\nodejs\

To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.

After that, reopen your command prompt and type

npm

This should work.

21
  • 5
    The reason I did not accepted answer was that I had that path entry already. The reason it was not working was different. I have given a thumbs up for your answer though
    – Suhas
    Mar 23, 2014 at 19:50
  • 6
    the semicolon separates the different user variables that you can have. So normally you already have some paths in your environment variables, and to add a new one, first you need to separate from the rest by adding a semicolon before the path you want to add.
    – Breno
    May 21, 2014 at 13:52
  • 7
    The node.js installer already put the path variable in for me. But I still don't have npm on the command line.
    – MrFox
    Dec 17, 2014 at 9:03
  • 10
    Did you reboot @MrFox ?
    – Breno
    Dec 29, 2014 at 14:49
  • 11
    1. Check Path (Environment variables) 2. Restart VS Code. If it still doesn't work try restart PC. If that doesn't work, break your pC
    – Marlon
    Jul 11, 2018 at 1:31
239

Don't forget to reboot your computer after installing node! That one got me.

10
  • 1
    Not sure if you need that if you install using Chocoletey.
    – Suhas
    Mar 13, 2014 at 13:33
  • 126
    You shouldn't have to reboot, but rather just close your terminal and open it again.
    – Catfish
    Aug 4, 2014 at 13:32
  • @Suhas … win 10 - admin PS prompt -choco install nodejs - restarted Code … STILL had to reboot
    – felickz
    Aug 31, 2018 at 20:47
  • VS Code updated itself. Had to reboot, nothing else worked.
    – TDP
    Oct 22, 2018 at 14:42
  • 1
    or "refresnenv" instead of exiting and launching a new terminal
    – atamata
    Jun 2, 2020 at 11:49
93

If you are using VS Code, close VS code and open again.

I tried closing Terminal and then opening new Terminal but it didn't work.

Restarting VS Code usually works!

2
  • 3
    also visual studio needs restart.
    – Flowra
    Dec 14, 2022 at 8:24
  • vs code restart work for me Mar 13, 2023 at 10:22
52

To elaborate on Breno's answer... For Windows 7 these steps worked for 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 Edit... button
  5. At the end of the Variable value, add ;C:\Program Files\nodejs
  6. Click Ok on the "Edit User Variable" window, then click Ok on the "Environment Variables" window
  7. Start a command prompt window (Start button, then type cmd into the search and hit enter)
  8. At the prompt (C:\>) type npm and hit enter; you should now see some help text (Usage: npm <command> etc.) rather than "npm is not recognized..."

Now you can start using npm!

1
  • 7
    On some systems it might be ;C:\Program Files(x86)\nodejs.
    – kaiser
    Sep 8, 2014 at 11:29
46

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

Reference: npm not recognized as internal or external command (Note: this is my own blog)

0
28

Just Download and Install Node.js from here https://nodejs.org/en/

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

You don't need any other configurations anymore, now you can use the npm command anywhere


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

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

Follow the steps below for Windows users:

  1. Go to My Computer Properties
  2. Click Advanced System Setting from the Left bar of a window.
  3. Now you have a System Properties window. Click Advanced
  4. Then, Click Environment Variable button
  5. Now you have Environment variable window: From System Variable, Select Path
  6. Click Edit
  7. At the end of the Variable value, add ;C:\Program Files\nodejs\

    Note: If you have installed nodejs on other drives then please act accordingly.

  8. Click Ok all the open dialogue box

Very important Note: "Close your Command Prompt And Restart Again" (It's very important because if you didn't restart your command prompt then changes will not be reflected.)

Now you can use the npm command anywhere

1
  • 1
    Thanks Udhav, that was helpful to me, especially the last bold note: Very important Note: "Close your Command Prompt And Restart Again" (It's very important because if you didn't restart your command prompt then changes will not be reflected.) ==> Thank you! Sep 7, 2020 at 4:14
28

I understand this question is really old and we have many answers, unfortunately, my scenario was different, thus a different solution.

If you started using nvm to manage the node versions after you install the node in your machine, most likely you will be facing the same issue.

enter image description here

I installed a version 10.15.3 and then I had to use another version as there is some tight dependency with one of my projects. Then I decided to install the nvm, while installing it asked, whether I need nvm to manage the version already installed on my machine which is 10.15.3. And yeah, I said Yes hoping that it will take care of that, unfortunately, it didn't.

I was always getting this error no matter I tried many other things mentioned in the other answers here, including setting the path. In the end, to fix that, these are the things I tried.

  1. Uninstall the node version installed, for example, nvm uninstall 10.15.3
  2. Make sure no other node versions are there, nvm list
  3. Then, install the version needed, for example, nvm install 10.15.3. This should give you an output as preceding.
Downloading node.js version 10.15.3 (64-bit)...
Complete
Creating C:\Users\SibeeshVenu\AppData\Roaming\nvm\temp

Downloading npm version 6.4.1... Complete
Installing npm v6.4.1...

Installation complete. If you want to use this version, type

nvm use 10.15.3
PS C:\Users\SibeeshVenu> nvm use 10.15.3
Now using node v10.15.3 (64-bit)
  1. Please note that from the above command, the npm is also installed.
  2. Now use the version you need, nvm use 10.15.3 and type npm

enter image description here

6
  • did you have to uninstall and install every time with NVM? i think i am actually having a similar issue. May 11, 2021 at 20:58
  • Yes, that should work. Again, npm command will not work if we do not run "npm use <version>" command.
    – Tarique
    Jun 27, 2021 at 4:34
  • This worked for me. Thank you! Nov 4, 2021 at 20:47
  • 1
    Thanks it worked bruh... i think after install nvm I forgot to do nvm use .... Jun 4, 2023 at 16:58
  • Sometimes all u need to do is switch versions using nvm. And npm will come back. That was what i did in my case
    – kamasuPaul
    Jun 10, 2023 at 5:39
22

Don't forget to run cmd as admin.

2
  • I installed Node outside Program Files and this fixed the problem. Thanks.
    – Pauline
    Jan 29, 2015 at 5:43
  • running as an admin is not a requirement to be able to use NPM!
    – Enrico
    Jun 3, 2023 at 17:21
16

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

C:\Program Files\nodejs\

I also had to remove that final backslash in order to have it work.

1
  • 2
    You write 'in addition' but the only change that I had to make was to remove the trailing slash in the Path system environment variable. Feb 23, 2015 at 16:32
13

I faced the exact same issue and notice that after installing node.js there was a new path entry in the user variable section for PATH with value --> c:\User\\AppData\Roaming\npm. Also the Path entry in the system variable is appended with --> C:\Program Files\nodejs. Now since user variable has preference over system you have two options to fix this. Either delete the path from user variable or correct the right path (C:\Program Files\nodejs). Restart CMD and it should work.

0
11

Set aside all the tips, just run the following line in cmd

> SET PATH=C:\Program Files\Nodejs;%PATH%
1
  • Worked for me when nothing else did
    – Justin
    May 23, 2022 at 0:43
5

If you're getting this error through a service account like Visual Studio TFS Build controller service or any other background service, make sure you restart the service after installing npm as the new PATH environment settings will not be picked up by those already running processes. I was getting same error through my build service but I had npm installed and running in the console.

5

You might have already received a response but this might help others since I experienced the same issue recently and this is what I did:

  1. Added a path for Powershell. For me, the path was C:\Windows\System32\WindowsPowerShell\v1.0

  2. Then, I opened the command prompt with administrative privileges and ran

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

  3. Next, choco install nodejs

  4. Restart and everything worked fine. Try opening the command prompt without admin privileges and run npm -v

Cheers.

4

Had the same problem on Windows 8.1 64 bit.
Turns out i get that problem if I start cmd by typing it in the path bar at the top of a folder window
or
when i shift right click in a folder window and then open command prompt from the list.

When I run cmd using Run or Just from the cmd.exe executable it works.

4

Step 1: install NodeJs

step 2: Set environment path

enter image description here

Step 3: Restart PC once

3

I installed nodejs following this AngularJS tutorial. the npm command did work 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.

3

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

  1. Click windows start button.
  2. Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
  3. You can run the Node.js Command prompt as administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."

and then it works from there...

3

I ran into this issue as well. It turns out Windows doesn't enjoy single quotes on the command line. The culprit was one of my npm scripts. I changed the single quotes to escaped double quotes:

'npm -s run sass-build'

to

\"npm -s run sass-build\"
3

I'm updating this thread with a new answer because I've found the solution to my miserable situation after not less than a week ...

For those still experiencing the error even though they have their path value set properly, check your pathext variable to have the value (default value in windows 7 +) : .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Mine was to set only to : .BAT and changing it solved the problem. I wonder why nobody brought this up ...

Hope this helps!

3

If everything looks fine. I would advice to check this for PATHEXT .CMD must be added. enter image description here

0
3

I don't know why most of user suggesting ; / in the command. I solved this by removing ; and /

Before

;C:\Program Files\nodejs\

After Solution

C:\Program Files\nodejs

You need to save them into system PATH variables

2

I ran into this problem the other day on my Windows 7 machine. Problem wasn't my path, but I had to use escaped forward slashes instead of backslashes like this:

"scripts": {
    "script": ".\\bin\\script.sh"
}
1

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

npm install -g cordova ionic

I faced the above error. I added 'C:\Program Files\nodejs' to my Environment Variable 'PATH'. But still was unable to get over this issue. Turned out that my PATH variable was longer than 2048 characters and so I was unable to 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 to install Ionic again. This worked for me.

1

for me adding path to PATH didn't do the trick. Run c:\Program Files\nodejs\nodevars.bat instead, it will do the job for you

1

Well in my case doing testing via Mocha i tried everything just to realize i have to remove single quotes around my test case script tag inside package.json.

I am running mocha test case on all *.test.js files as can see 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, just in case someone else also gets stuck on this.

1

JUST RESTART your VS Code or Terminal and type npm

1

sometimes you need just to RESTART you computer after the installation of node.js; and it work for me

0

Check npm config by command:

npm config list

It needs properties: "prefix", global "prefix" and "node bin location".

; userconfig C:\Users\username\.npmrc
cache = "C:\\ProgramData\\npm-cache"
msvs_version = "2015"
prefix = "C:\\ProgramData\\npm"
python = "C:\\Python27\\"
registry = "http://registry.com/api/npm/npm-packages/"

; globalconfig C:\ProgramData\npm\etc\npmrc
cache = "C:\\ProgramData\\npm-cache"
prefix = "C:\\ProgramData\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\WINDOWS\system32

In this case it needs to add these paths to the end of environment variable PATH:

;C:\Program Files\nodejs;C:\ProgramData\npm;
0

If you used ms build tools to install node the path is here:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\NodeJs
0

You don't need to "install" Node.js. Just download the package from https://nodejs.org/en/download/releases/ and extract the contents somewhere. Then, in a command prompt, you can navigate there using cd. Then you can run npm from that location. While you will have to do the cd C:\Users\YourAcct\Documents\node-v16.13.0-win-x64 or similar command before you can run it, it's a way to get it onto your computer and run npm without having to be an admin or editing environmental variables.

Not the answer you're looking for? Browse other questions tagged or ask your own question.