npm commands are not getting recognized in Windows PowerShell & Command Prompt - npm

Installed the latest version of Node JS without additional installation of Chocolatey.
Latest LTS Version: 18.13.0 (includes npm 8.19.3)
Environment variables are configured appropriately.
System variable "Path" has a reference to the "C:\Program Files\nodejs" where it is installed.
Despite this, the npm command is not getting recognized in Windows PowerShell & Command Prompt. Shows some blank lines without any error/warning/any relevant message.
Am I missing something here?
Installed Node JS from https://nodejs.org/en/download/ - 64 bit, LTS using Windows Installer

Related

Running a express server from WSL ( UNC paths are not supported )

I'am trying to run a express server from a WSL terminal in VS Code.
However, whenever, I run the command npm run dev I get the following error:
'\\wsl$\Ubuntu\home\simao\legalize-backend'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
I assume it has something to do with the path from windows to the folder in the WSL directory.
Which one is the right path format or what should I do to make this one valid ?
Searching I found that you can
You can solve this problem(UNC Paths not supported) by mapping a
normal drive letter to the path that has the UNC path.
But how do i map a normal drive letter to the path ?
This happens because whatever tool you are using is trying to run commands via cmd.exe and cmd.exe does not understand UNC paths (those starting with \\... rather than drive letter). Mapping UNC path to drive will convert it to drive letter path.
To map WSL path to Windows drive run cmd.exe (Command Line) and type following command:
net use X: \\wsl$\Ubuntu\home\simao
Where X: is drive that will be created (you'll see it as network drive in e.g. My Computer) and \\wsl$\Ubuntu\home\simao is WSL path to root of that drive. wsl$ is special hostname that tells Windows to connect to WSL, Ubuntu is distribution name under WSL, then finally \home\simao is path to directory in Ubuntu distribution that should be mapped.
I confronted the same situation yesterday. I assume maybe it was something wrong with my npm. Then I checked the npm path with which npm, and I found that my npm was mounted D:\nodejs\npm in Windows (exactly /mnt/d/nodejs/npm in screen).
I guess WSL uses CMD.exe to start npm from Windows described in CMD.EXE was started with the above path as the current directory.
So maybe I can just install a new npm in WSL to solve this. Node Version Manager (nvm), is the most popular way to install multiple versions of Node.js. And each version of nodejs has its own version of npm. Just follow the link below.
Install nvm, node.js, and npm
Plus, if you have Permission denied, use npm uninstall xxx to remove your dependencies you've installed, and install your dependencies again.

NPM Package Error- 'newman' is not recognized as an internal or external command

I have installed the latest version of Newman (3.10.0) in my 64-Bit Win 10 Machine.
C:\Users\ABC>npm install -g newman
C:\Users\ABC\AppData\Roaming\npm\newman -> C:\Users\ABC\AppData\Roaming\npm\node_modules\newman\bin\newman.js
+ newman#3.10.0
added 195 packages in 57.852s
However, I am not able to use the newman and I am getting below error while accessing.
C:\Users\ABC>newman -h
'newman' is not recognized as an internal or external command,
operable program or batch file.
I have added an environment variable for the NODE_PATH pointing to the newman directory C:\Users\ABC\AppData\Roaming\npm\node_modules\newman
but no luck. Could some one please help.
Adding in the Path variable under Environment Variable solve the problem even if we don't add in NODE_PATH
C:\Users\ yourusername \AppData\Roaming\npm
After doing this reopen command prompt
The issue was fixed after troubleshooting with the Node Application. A previous version of Node (32-bit) was installed in my machine and it was not completely removed after I did an uninstall. When I installed Node 64-Bit both entry was present in the environment variable and caused a conflict.
When I manually deleted both installation folder and the env variable the newman worked correcly.
I have installed node, vc redist and newman once (on clear windows 7 64 bit) and the issue is looks like related to wrong newman installation. Both newman and node should be installed from administrator session (not just with admin privileges). I have installed newman from regular user, system path setting are correct, but user environment was not set:
path=C:\Users\gagarin\AppData\Roaming\npm
So I have copied
C:\Users\<regular_user>\AppData\Roaming\npm
to C:\Users\admin\AppData\Roaming\npm and run C:\Users\admin\AppData\Roaming\npm\newman.cmd from administrator session. After that newman command became work in admin session. Sadly it works in regular user session only if I type full path to newman like
Blockquote
c:> C:\Users\admin\AppData\Roaming\npm\newman run ....
I was also getting the same error and I have followed the below steps to troubleshoot it-
1. Know what user is running jenkins, a simple way is Create a jenkins job and in its Build section run the command
whoami
2. If it shows System user, then do the following-
2.a. Set C:\Users\I823285\AppData\Roaming\npm and C:\Users\I823285\AppData\Roaming\npm\node_modules\newman\bin in SYSTEM ENV. VARIABLES.
b. Restart Jenkins by running CMD as ADMIN, and go to Jenkins installation folder, then enter jenkins.exe restart.
c. Re-build the project
SUCCESSFUL!

Visual Studio Code (Windows) Not Detecting Global NPM Modules

I'm experiencing an issue where Visual Studio Code in Windows 10 is not able to detect globally installed NPM packages within the Integrated Terminal.
For example, if the windows command prompt I install #angular/cli via command npm install -g #angular/cli, within that command prompt I can execute #angular/cli commands such as ng --version without error. After that global npm module install, within Visual Studio Code, performing the same ng --version gives me the error:
The term 'ng' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
I can however within the integrated terminal successfully perform commands such as npm -v and node -v.
I have the following items in my system environment variables
C:\Program Files\nodejs\
%AppData%\npm
Are there Visual Studio Code user or system environment variables I'm missing to allow detection of global npm modules?
Thank you for any help you can provide.
Visual Studio Code must be "Run as Administrator" for working Terminal Commands.
I was able to resolve the issue and use global npm commands in Visual Studio Code by modifying my system environment path variables to position %AppData%\npm before %ProgramFiles%\nodejs\ per npm troubleshooting tips
no need to do anything else just follow below steps -
right click on my computer (this pc).
go to properties.
click on advanced system setting.
click on environmental variable.
select path variable from system variable.
click on edit button.
add %AppData%\npm and %ProgramFiles%\nodejs\ at top of the list.
8 click on ok. ok. ok
restart your system.
after restart open visual studio code as run as administrative mode.
Enjoy...............!!!!!
Run Visual studio code as an administrator. Then type ng command. It should work
Reboot your computer , this worked for me
If you have entered the environment variable and it is still not recognized and if you don't want to reboot your computer because you have so many things running then just reboot your Visual Studio Or Visual Studio Code and then Open Terminal (ctrl + `) and run
npm install
Now it will work fine.
You can resolve the issue by opening the VS Code Terminal and type
npm install -g #angular/cli
This should resolve the issue.
Run powershell or cmd prompt in admin mode.
Check if npm and node commands work (if not, then check environment variables as others have mentioned).
Update node using npm [https://stackoverflow.com/questions/18412129/how-can-i-update-
npm-on-windows]
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install -g npm-windows-upgrade
npm-windows-upgrade
Run npm install -g #angular/cli
Run ng --version in Visual Studio Code to see if it's now working.
If you do not have access to Environmental variable (office machines).
You can try to run command like this:
npm run <your angular command>
it works as well, just need to add npm run before ng command
Example -> npm run ng g c shop/cart
I found that adding %AppData%\npm to your Path variable made it work for PowerShell and the Command Prompt, it still did not work for the integrated PowerShell in VS Code for me.
When I changed it from %AppData%\npm to the actual path C:\Users\<USER>\AppData\Roaming\npm where <USER> is your user directory, and reopened VS Code it started working.
Additionaly to all the good advice here, make sure that you have node.js installed on your machine.
To me the solution was adding the extensions for npm:

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

I'm getting:
'npm' is not recognized as an internal or external command, operable program or batch file.
when I issue:
npm install -g bower polyserve
Even though I have downloaded node.
I think you have not defined the path of nodejs in Environment Variables on the System Properties.
Add ;C:\Program Files\nodejs\ (path of your nodejs installed directory)
To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.
Then reopen cmd prompt and type npm again.It should work now.Hope it helps.
You can do one more thing if still it does not work.Reboot your machine after installing node.
Set path for node.js in your environment variables.
To do this:
right click on MyComputer->properties->advance system setting-> Environment variables-> select & edit "Path" variable in System variables.
Add C:\Program Files\nodejs\; in path
Restart your command prompt
Type node --version in a new console window, the version number should appear as a response.
I would recommend using https://github.com/coreybutler/nvm-windows instead of directly installing a version of node, as it is common to switch between node versions for different projects. Following are the instructions to set it up.
Open PowerShell with 'Run as Administrator' option (Admin role is required for creating symlink)
Check if nvm is installed:
nvm version
If not, follow instructions on https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows to install it.
If nvm was installed, check if nodejs is in system path:
$Env:Path
If nodejs (likely 'C:\Program Files\nodejs') is not in the path and 'nodejs' symlink file exists in the directory 'C:\Program Files', then add it to the path as described by Vikas Sharma.
If 'C:\Program Files\nodejs' is in the path and symlink file doesn't exists in the directory, list installed node versions using:
nvm ls
Then create the symlink using (needs Admin role):
nvm use <node version>
Check if npm is working now:
npm --version
I had the same issue. Environment variables were all in place (as suggested by the user above). I was using node 8.9.4. Changing node version to 8.16.0 worked for me.
If node is there but npm only not found (which is my case), then
if you have the downloaded node.js in your (windows) pc run the repair option it will do the rest.
Close the cmd window and reopen and test it by running the command
npm -v
Now it will show you the npm version.

Unable to execute cordova

I was able to install cordova originally but I am now unable to use it.
I have uninstalled using npm uninstall -g cordova, and this seems to be working as expected. When I attempt to reinstall it using the command npm install -g cordova, the installation seems to run, but when attempting to run cordova commands I get the cordova is not a recognized internal or external batch command message. This is on a Windows 7 Pro x64 machine. What could be the possible causes and fixes for this?
Do you already had the apacha ant ready? If not, try to download that from apache.org and put the patch folder where you extract this to your path variable.
You should add the cordova installation path folder to you path environment variables