371

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Suhas
  • 7,919
  • 5
  • 34
  • 54
  • 18
    After adding to the `PATH`, did you restart the command line? `PATH` is only loaded when initializing new command line sessions. – Davin Tryon Jan 08 '14 at 10:30
  • 2
    Yes Davin, I have restarted command line several time now – Suhas Jan 08 '14 at 10:52
  • I've got "C:\Program Files\nodejs\" in my system `PATH` and everything working on Windows 7. – Davin Tryon Jan 08 '14 at 12:00
  • 7
    Can you open a new command prompt and type `PATH` (hit ) and double-check that you see "C:\Program Files\nodejs\" in there? – Davin Tryon Jan 08 '14 at 12:02
  • 2
    Yes, I do have `C:\Program Files\nodejs` in `PATH` – Suhas Jan 08 '14 at 12:54
  • in general, sometimes you have to add the \ so: "C:\Program Files\nodejs\" instead of "C:\Program Files\nodejs" – Alexander Mills Dec 18 '14 at 08:44
  • Old question but I ran into this problem today on my Windows 7 machine. Problem wasn't my path, but I had to use escaped forward slashes instead of backslashes like this `script: ".\\bin\\script.sh"` – Daniel Lizik Sep 07 '15 at 22:59

41 Answers41

537

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.

Breno
  • 5,952
  • 1
  • 20
  • 25
  • There was a problem with my PATH variable which I have managed to fix – Suhas Feb 21 '14 at 09:28
  • My path had a quote that was not terminated and thus acting evil. Terminating the quote made it work – Suhas Mar 22 '14 at 23:11
  • 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 '14 at 19:50
  • That solved the issue for me. Could you give an explanation on how the semicolon `;` fixes it and what it's for? – caiosm1005 May 20 '14 at 01:13
  • 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 '14 at 13:52
  • 4
    take me little bit time find How to add ;C:\Program Files\nodejs\ on "User variable". Sharing this below: 1:Open the System Properties window (Start-->Settings-->Control Panel-->Performance and Maintenance-->System). 2.Select the Advanced tab. 3.Click on the Environment Variables button. 4.Click New button under the "User variables" 5.add "Path" and ";C:\Program Files\nodejs\" – Wen Aug 28 '14 at 04:49
  • 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 '14 at 09:03
  • 9
    Did you reboot @MrFox ? – Breno Dec 29 '14 at 14:49
  • 1
    Looking at number of upvotes to this answer, I think I should accept this answer. – Suhas May 28 '15 at 06:28
  • 1
    I added ;C:\Program Files\nodejs\ at the end of path, and reopened cmd, but still getting the same error(npm is not recognized as an internal or external command). Any clue? – merve bıçakçı Jan 18 '16 at 08:50
  • Do you have npm at the path actually? – Suhas Jan 22 '16 at 21:46
  • For me the path was C:\Program Files (x86)\nodejs\ – irperez Jan 24 '16 at 02:26
  • @Breno I have same problem which is raise merve bıçakçı have then what i do it then it will solve please help me – VjyV Oct 04 '16 at 18:52
  • 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 '18 at 01:31
  • What work for me was to close the IDE and open back again. if still not working make sure in the webstorm settings under node.js and NPM that it recognize the path you added to the system variables – dubi Apr 15 '19 at 10:05
  • Or more generally, along the lines of this answer, do a search on 'NodeJs' to locate the folder containing the npm.command file, and put that path in your environment variable. – ouflak Jun 12 '19 at 06:45
  • 1
    For me it worked by removing the last backslash \ and without the starting semicolon ; on Windows 10. – AlexioVay Jun 28 '21 at 08:05
  • Nothing I do seems to help. Is there anything else that could fix this issue? – Aluminium22 Nov 02 '21 at 16:22
  • After setting the path variable if still not working, **Close your Command Prompt And Restart Again** – chathura May 15 '22 at 20:21
  • 1
    In Windows 11, Environment variables can be searched with the phrase "Edit the System Environment Variables" from Windows search in the task bar. – Onat Korucu Feb 14 '23 at 10:34
226

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

paul-shuvo
  • 1,874
  • 4
  • 33
  • 37
user3414680
  • 2,333
  • 1
  • 11
  • 2
  • 1
    Not sure if you need that if you install using Chocoletey. – Suhas Mar 13 '14 at 13:33
  • 117
    You shouldn't have to reboot, but rather just close your terminal and open it again. – Catfish Aug 04 '14 at 13:32
  • @Suhas … win 10 - admin PS prompt -choco install nodejs - restarted Code … STILL had to reboot – felickz Aug 31 '18 at 20:47
  • VS Code updated itself. Had to reboot, nothing else worked. – TDP Oct 22 '18 at 14:42
  • Like @Catfish said, a reboot isn't necessary. Just exit the terminal and launch a new one. That loads the changed path variable into the environment. – Andreas May 15 '20 at 10:22
  • 1
    or "refresnenv" instead of exiting and launching a new terminal – atamata Jun 02 '20 at 11:49
  • fixed it for me on win 7 system – ihkawiss Feb 09 '21 at 13:06
  • If you using IntelliJ, you need to close *all* open windows, not only the one with open terminal. Only then Intellij process actually terminates. As stated in comment above, no need to reboot – Illidan Mar 21 '21 at 12:25
  • If you have vs code failing even after restart (or even without restarting) instead of closing and reopening code, try to kill the terminal (with the trash bin icon) and then start a new one, that worked for me. – Yogurtu Nov 09 '21 at 15:47
  • LOL this one worked for me – momal Sep 30 '22 at 20:30
70

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.

Re-Starting VS Code works!

codemirror
  • 3,164
  • 29
  • 42
51

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!

Community
  • 1
  • 1
Luke
  • 18,811
  • 16
  • 99
  • 115
44

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)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
27

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

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
  • 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! – HassanSh__3571619 Sep 07 '20 at 04:14
22

Don't forget to run cmd as admin.

Raul
  • 963
  • 2
  • 11
  • 31
20

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sibeesh Venu
  • 18,755
  • 12
  • 103
  • 140
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.

Community
  • 1
  • 1
gbgnv
  • 265
  • 3
  • 8
  • 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. – Scott Munro Feb 23 '15 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.

Ashu
  • 1,703
  • 4
  • 16
  • 23
10

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

> SET PATH=C:\Program Files\Nodejs;%PATH%
مهدی
  • 333
  • 3
  • 6
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.

shet_tayyy
  • 5,366
  • 11
  • 44
  • 82
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.

Ehsan Mahpour
  • 131
  • 1
  • 8
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.

jacobian
  • 141
  • 9
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.

miva2
  • 2,111
  • 25
  • 34
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...

S.Droid
  • 79
  • 2
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!

A.KHOUS
  • 31
  • 1
3

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

Gitesh
  • 649
  • 7
  • 12
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

Hadayat Niazi
  • 1,991
  • 3
  • 16
  • 28
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"
}
Daniel Lizik
  • 3,058
  • 2
  • 20
  • 42
2

Step 1: install NodeJs

step 2: Set environment path

enter image description here

Step 3: Restart PC once

Sushil
  • 670
  • 7
  • 14
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.

Sundar Ram
  • 1,371
  • 1
  • 8
  • 4
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

Cheburek
  • 2,103
  • 21
  • 32
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.

Ylama
  • 2,449
  • 2
  • 25
  • 50
1

JUST RESTART your VS Code or Terminal and type npm

Ashish Gupta
  • 105
  • 1
  • 5
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;
Pax Beach
  • 2,059
  • 1
  • 20
  • 27
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
Post Impatica
  • 14,999
  • 9
  • 67
  • 78
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.

vapcguy
  • 7,097
  • 1
  • 56
  • 52
0

The issue is with system policy. I have tried the following comments in powers heel then it is started working

$> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force 
$> npm install -g npm-windows-upgrade 
$> npm-windows-upgrade

I got this idea from the following link

Jerin Stephen
  • 71
  • 2
  • 9
0

After adding environment varible path restart your machine maybe this will work. it work for me. i was using vm.

Flame alchemist
  • 107
  • 1
  • 4
0

This problem also occurs if you have installed NVM(Node version manager). And then we try to install through the "npm install" command.

Solution:

  1. Just change your environment variable named "NVM_SYMLINK" to "Path for the folder you installed Node.exe".
  2. And restart your PC, Your problem will be solved.
0

This issue occurred to me when I tried to use another version of node using nvm. I was installing node from outside and then tried to use another node version using nvm. That's why npm was not recognizable. So, here's what I did:

  1. remove node.js
  2. install the specific node version using nvm

nvm install 12

  1. use that version using nvm

nvm install 12.22.12

0

I ran into the same problem after installing node with nvm on my machine (windows). The path in env variables contains the following entries:

  1. C:\Users\amohanan\AppData\Roaming\nvm
  2. C:\Program Files\nodejs

By deleteing the C:\Users\amohanan\AppData\Roaming\nvm from the path and restarted the cmd fix my issue.

Arya Mohanan
  • 577
  • 5
  • 8
0
  1. install nodejs.

  2. configure nodejs path into environment verables.

  3. check nodejs version by

    node -v

  4. run

    npm install -g typescript

  5. check typescript version

    tsc --version

note: if still not working restart your computer.

0

For people who use NVM to manage node version:

Just keep version of NVM up-to-date.

My case was that when I installed node with nvm, there was lack of npm in the particular version of node (nvm install nodes in its own subfolders).

Once NVM updated, just reinstall node (npm is installed automatically).

Bronek
  • 10,722
  • 2
  • 45
  • 46
0

I had to add a proxy statement in my npm config file.

To open the config file type: npm config edit

A text file opens: .npmrc
"dot npm rc" found in c:\users<myid>.npmrc Not hidden on my PC.

contents: I had to add the lines for the proxy server.

;;;; ; npm userconfig file: C:\Users<myid>.npmrc ; this is a simple ini-formatted file ; lines that start with semi-colons are comments ; run npm help 7 config for documentation of the various options ; ; Configs like @scope:registry map a scope to a given registry url. ; ; Configs like //<hostname>/:_authToken are auth that is restricted ; to the registry host specified.

http-proxy=http://wxyz.abcde:####

https-proxy=http://wxyz.abcde:####/

registry=https://registry.npmjs.org/

;;;; ; all available options shown below with default values ;;;;

user3784130
  • 71
  • 1
  • 2
-1

You only need to add it to your environment variables:

1st: write env in the search bar

or Right click start button -> System -> Advanced system settings -> Environment Variables... -> Select PATH

write env in the search bar

2nd: click on the new button and add the following path:

;C:\Program Files\nodejs\

choose path

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
-1

Adding ;C:\Program Files\nodejs\ in the environment variable path solve the problem

-1

After trying out all sorts of solutions I could find on both YouTube and here on stackoverflow to fix this issue, all efforts was to no avail.

I guess the problem must have been because node must have been moved to a different folder other than <C:\Program Files> so what I did was that I uninstalled node and then re-installed it and everything got back to normal.

I believe you should be fine after this process.

Dharman
  • 30,962
  • 25
  • 85
  • 135
-4

We need to install nodejs and nothing else do we need to do and then simply use command prompt and change directory to the project in which you want to install npm and then use npm install command. It has worked for me.