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
where npm
gives me c:\User\<Username>\AppData\Roaming\npm
which has nothing in itC:\Program Files\nodejs
. Opening a command prompt in this directory makes npm
work fine.C:\Program Files\nodejs
to PATH
only to get the same error again that npm is not recognized
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?
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?
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.
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."
and then it works from there...
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.
Don't forget to reboot your computer after installing node! That one got me.
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"
}
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:
Then I opened cmd prompt with administrative privileges and copied this
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
into the cmd prompt.
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.
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;
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.
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
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:
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.
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 - Close CMD Window
2 - Add C:\Program Files\nodejs
to PATH variable
3 - Open new CMD, type: npm -v
and enjoy ;)
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!
Don't forget to run cmd as admin.
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.
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.
Adding the environment variable for nodejs path will solve this problem https://codetolive.in/development/npm-is-not-recognized-as-internal-or-external-command-operable-program-or-batch-file/
For Windows users: A picture tells a thousand words
Reference: npm not recognized as internal or external command (Note: this is my own blog)
To elaborate on Breno's answer... For Windows 7 these steps worked for me:
;C:\Program Files\nodejs
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!
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\"
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!
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
follow just 2 steps 1.Download nodejs manually now go to that path like C:\Program Files\nodejs\ 2. Next add a new path like name : path and variable name :C:\Program Files\nodejs\ click ok and close cmd prompt . reopen and just type npm in prompt
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.
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.
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.
For windows8
right click my pc properties
then click environment variables
user variable or System variables >> new >> put variable name and path : like this C:\Program Files\nodejs
Then ok
now open cmd and type npm it will work
Source: Stackoverflow.com