Node cli on Msysgit on WIndows 10 - node.js

I recently decided to pick up Node on my personal laptop, which I upgraded to Windows 10, and the Node cli seems to hang when I try to run it.
Simply typing node on the console will not initiate the interface, and to do anything else I need to Ctrl+C out of it.
Additionally, running some npm commands take longer than they used to on my laptop. More noticeably, npm init seems to hang after confirming the information to be written to package.json.
Node version is 4.0.0
npm version is 2.14.2
Are there any known issues with Node and npm on Windows 10?
Edit:
After some troubleshooting, I've figured out the error only happens on Msysgit. Neither of the issues happen on the standard command prompt of Windows.

I had the same issue on Windows 7 with Node version 6.11.0 and Msysgit's MINGW64 terminal window.
The problem was caused by the an alias provided by Msysgit as demonstrated below:
$ alias node
alias node='winpty node.exe'
The solution is to run the command:
$ unalias node
Then node will run correctly.
You can add the unalias node command into your .bashrc file in your HOME directory to make this permanent.
Good luck!
Jeff

Related

Node installation messed up on MacOS

I have screwed up the installation of node on my computer over the course of a few months by deleting using rm and reinstalling with brew. I recently managed to fix the 'node' command such that 'node -v' works fine.
However, the command 'npm' is not found. Additionally, every time I open a terminal I get the following text:
Last login: Sun Dec 19 22:33:22 on ttys002
N/A: version "N/A -> N/A" is not yet installed.
You need to run "nvm install N/A" to install it before using it.
The default interactive shell is now zsh.
This leads me to believe that I have some issue with my bashrc file.
Does anyone have any idea what steps I can take to resolve this issue, or if it would be a better option to simply factory restore my computer?
Use nvm to install any version of node and npm (e.g: v16.13.1).
type nvm alias default v16.13.1 in your terminal and then type nvm use default

zsh: command not found: npm in the command line

I downloaded nodejs from nodejs.org on my Mac. When I type node in the command line in the terminal I get the following:
davidd.christie#Davids-MacBook-Pro ~ % node
Welcome to Node.js v12.18.0.
Type ".help" for more information.
> .exit
davidd.christie#Davids-MacBook-Pro ~ % ls
Applications Documents Library Music Postman
Desktop Downloads Movies Pictures Public
davidd.christie#Davids-MacBook-Pro ~ % cd Desktop
davidd.christie#Davids-MacBook-Pro Desktop % ls
UBS Candidate Benefits Modeler.pdf my-express-server
intro-to-node node-course
davidd.christie#Davids-MacBook-Pro Desktop % cd intro-to-node
davidd.christie#Davids-MacBook-Pro intro-to-node % npm init
zsh: command not found: npm
davidd.christie#Davids-MacBook-Pro intro-to-node%
It is my understanding that npm automatically downloads once you download node. I tried to initiate npm and got the following message (please see the above code in typed in the command line):
zsh: command not found: npm
I am not sure what to do from here. I have been looking at some of the code on here. I am so confused as to what to do. I am fairly new to coding. Can someone please help and out step by step as to what I need to do? I would be forever grateful.
It depends on how you have installed node. First check the version of your node.
node --version
It should give your node version. In my case it is v10.15.0. Now to find where this node is coming from use command.
which node
It will give you output as /Users/samundra/.nvm/versions/node/v10.15.0/bin/node. It shows that my node is installed at /Users/samundra/.nvm/versions/node/v10.15.0/. Usually npm and node both are placed at same location $NODE_HOME/bin/node, $NODE_HOME/bin/npm. Here $NODE_HOME is /Users/samundra/.nvm/versions/node/v10.15.0.
If we further check where $NODE_HOME/bin/npm by using
ls -al /Users/samundra/.nvm/versions/node/v10.15.0/bin/npm
We find that it's linked to npm-cli.js
lrwxr-xr-x 1 samundra staff 38 May 11 12:08 /Users/samundra/.nvm/versions/node/v10.15.0/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
So, npm is symlinked to npm-cli.js which can be found at $NODE_HOME/lib/node_modules/npm/bin/npm-cli.js.
With this information now you can figure out whether your node and npm has been installed properly or not. Furthermore, If this is your first time installing node, try closing and re-opening your terminal. Most terminals need to re-initiate sessions after populating environment variables which are used based on installation method that you have used.
I hope this has answered your curiosity. If you feel so then please do not forget to mark it as answer.
Suggestion:
When you feel you have understood how node and npm work. Then you can move to use Node Version Manager (Nvm). It allows you to install multiple versions of node on same machine. You can switch between them using commands like
nvm list: List available node version
nvm use {node_version}: Install Node version and use it
This is quite helpful when you will have to work on different projects that require different version of nodes.
I faced the same issue. Actually you need to edit your .zshrc file
Open .zshrc file - sudo nano ~/.zshrc
Add source $(brew --prefix nvm)/nvm.sh
Save file and restart terminal

Is nvm is relevant for node these days in windows, should I use it? and if yes why?

When I tried installing nvm from website -
https://github.com/coreybutler/nvm-windows
everything went good, except the nvm use, even when I execute this command this doesn't seem to do its job properly though no error is thorwn by the terminal(cmd). When I try to use
node -v
it doesn't show the version number of node, that means node is not installed. And same goes witht the
npm -v
, this too doesn't show the version number, it hasn't been finding the executable. Everything works fine, that I install nvm install too. nvm list says there it is, and it donwloads and saves it the its user/appdata/nvm folder,(I checked it). But still cmd can't find the executable. Do I manually need to set the path for the node folder that's located in the roaming/nvm/node folder.
https://github.com/coreybutler/nvm-windows/issues/221#issuecomment-262363222
This comment solved the problem with one go, I guess the key was to use powershell, now node and npm works like smoothie. ;D

cordova is installed but not starting up

I installed node.js 8.9.3 and a successfully installed with following message
This package has installed:
• Node.js v8.9.3 to /usr/local/bin/node
• npm v5.5.1 to /usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
I run following command in terminal mac ...
$ $PATH
And i get following return..
-bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory
Q1. What does that last line mean? No such file or directory?
.. after that i run following commands..
$ which node
And following is response
/usr/local/bin/node
and similar for
$ which npm
And following is response
/usr/local/bin/npm
I think everything is fine till now..
Now i installed ...cordova typing..
$ sudo npm install -g cordova
It is installed and the next lines after completing installation i see ..
/Volumes/macHDD/Users/samz/.npm-packages/bin/cordova -> /Volumes/macHDD/Users/samz/.npm-packages/lib/node_modules/cordova/bin/cordova
+ cordova#8.0.0
updated 1 package in 27.977s
Q2. is it successfully installed? if so.. why is this not as global?
when i test typing
$ which cordova
terminal says nothing.. I also tested typing
$ cordova -version or $ cordova --version .. or even if i type
$ cordova create hello com.example.hello HelloWorld
I am "slapped" by terminal :(
-bash: cordova: command not found
...
in the last night. i was successful in installing cordova, and I created 2 test apps.. i was able edit them, even I run those apps on android emulator and on my ios device+emulator.
during building/preparing one of my app, I tried to create one more app project through a seperate terminal instance. And there I saw .. like no cordova.
I terminated first instance where cordova was working.. and reopened terminal to test if this is an issue.. and yes.. it was .. I could never work on cordova again.
Can somebody tell me what is the issue. ?.
it's very irritating now.
Thank you
I don't know how this is resolved..
I reinstalled node, npm, java, cordova (several times), but nothing could resolve.
and today .. i upgraded node9.3.0 from node8.9.3.. but still the same errors.
Now i had..
Muhammads-MacBook-Pro:colors muhammadfarooqi$ node --version
v9.3.0
Muhammads-MacBook-Pro:colors muhammadfarooqi$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
Muhammads-MacBook-Pro:colors muhammadfarooqi$ npm -version
5.5.1
Muhammads-MacBook-Pro:colors muhammadfarooqi$ cordova -version
8.0.0
i was about to kill myself.. but i found something on the internet with some other issue.. and i run the same command.
sudo rm -rf node_modules
sudo npm install
and then i installed cordova.
and wow... cordova is there :)
i dont' know what exactly was the solution .. I dont' know what this line of code did.. I know the above line removed node_modules and 2nd lines installed npm.. and now I am seeing cordova is running.
Please somebody, if my solution works for anybody, kindly comment. thank you
Your first issue is because you typed just $PATH. This is then expanded to its value, and then the shell attempts to execute it, which is obviously not possible.
To check your current PATH, type echo $PATH instead.
Your second issue is probably due to a partial configuration to use a user-specific global package directory.
By default, packages are installed in /usr/local/lib/node_modules, with symlinks for binaries in /usr/local/bin, which requires root access (sudo). You have at one point configured npm to install in a different directory (~/.npm-packages), but did not include the bin sub-directory in your PATH.
So you need to either finalise the configuration (see https://docs.npmjs.com/getting-started/fixing-npm-permissions for details), or revert to using /usr/local.

npm.cmd closes instantly after few seconds

I'm learning nodeJs. I managed to run nodejs commands on cmd and it works fine. Now I want to install express framework and for that in the tutorial I'm following it asks to type sudo install -g express on npm command prompt. So I typed npm in my windows search, and clicked on it. Right after few seconds less than 3 it closes straight away.
I found that npm.cmd exist in nodejs directory where node.exe found. What could be the problem here. If I were to type the above mentioned command in windows cmd, it says sudo is unrecognized program.SO must I use npm cmd?
After running cmd.exe , I guess you would have node installed but still run node -v , it should respond with the version meaning it's working.
Now if you want to explicitly install express.js you just have to run on, the command prompt itself,
npm install express -g.
Anyways you can follow this link from their official website. Hope it helps. Also sudo is a program for Unix like operating systems, just in case you needed it.

Resources