I installed nodejs on WSL2, but cant call it from windows - node.js

I have installed Node 18 on Ubuntu on WSL2 in Windows 11. (plus eslint, which is the main end goal) When I'm in the Ubuntu terminal, everything works fine. I can even eslint my code on the windows file system via /mnt/c/somefolder/... - cool!
When I try to call it from the Windows command prompt, I get "command not found"
C:\Windows>wsl node --version
/bin/bash: line 1: node: command not found
Other standard linux commands work fine, e.g. wsl ls or wsl nano foo.txt work as intended (though the current directory differs)
I'm guessing it's something about a PATH to node, but my Google-fu has failed me for a solution.
EDIT, FIXED (sort of): This seems to be NVM related. When I do a basic install of a single version of node in /usr/bin using Ubuntu apt-get (doing the tricks to get the more recent v18.2 LTS) it all works o.k. I don't need NVM for now...
EDIT 2
I can't get the VSCode (running under windows, with the ESLint extension) to connect to the node and eslint code under WSL. Which might just be impossible. Is it?

Related

What could make my VScode terminal give different results than my Gitbash terminal?

I'm trying to check my Node.js install version and when I type node -v in Gitbash I get the version number back, but when I type it in VScode terminal running Gitbash I it says what I ran was not a command.
I don't know if this matters but all of the relevant programs are installed in the same location (C:\Program Files):

Node and npm not found after restarting macOS

I am using my corporate's laptop and am a new mac User (used Ubuntu before) :
OS: macOS Monterey Version 12.2
There are two accounts, administrator and mine - I don't have sudo rights. To install homebrew without administrator rights, I followed this Installation.
To install the node - I used brew install node. Both node -v and npm -v were working. When I restarted the laptop, I cannot find node/npm.
On running $ node -v, I get -bash: node: command not found (I changed my default terminal from zsh to bash and the output is the same for both of them)
I tried this solution but couldn't find nvm in the system. Am new to mac and I believe nvm is some kind of package manager like homebrew so this solution is not applicable to me (correct me if I am wrong).
How can I install things in my system without sudo rights and keep them permanently(like node)?
EDIT:
(After adding brew to the PATH) On running - brew list|grep node, I got - node
$ echo $PATH gives /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/parthkapadia/homebrew/bin
EDIT2:
Adding brew to path solved the issue, now I can even access node and npm (even after restarting). I used this site to add homebrew/bin to path (in zsh terminal)
The issue was homebrew's path. It was not added to the PATH variable.
When I restarted the system, homebrew was no longer in the PATH (as it was temporarily added probably when I installed it). As homebrew was not added to PATH, the terminal didn't recognize brew or any package installed using it like node or npm.
I solved it by adding Users/username/homebrew/bin to PATH. The steps I followed are -
cd - to move to the home directory
touch .zshrc to create .zshrc file as it didn't exist
nano .zshrc to open the file for editing
Added export PATH=$PATH:/Users/yourusername/homebrew/bin in the file (this appends homebrew/bin to the PATH variable)
Now the terminal can recognize brew and hence node and npm too.
Refer this for more detailed explanation on how to add to PATH in macOS.
Thanks to all the people who helped in the comments.

I have installed nodejs on windows how should i use it in WSL?

I am having problem using libraries installed on windows to WSL and vice versa. I don't want to install not just nodejs but other things twice just to use it in WSL and also in normal text editors like VS code, atom, etc.
The complete instruction can be found here set-up-on-wsl
If you are too busy to follow the link, follow these steps in the WSL:
Use curl to install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
For installing NodeJs (lts)
nvm install node --lts
You can also install specific node version. Check all commands uses by typing nvm in your terminal.
Done Node has been successfully installed in your WSL, nvm ls will list all the installations.
You can use the Node installed in your WSL for developing. Point to your working directory and use code . to open VSCode. Also, if you want to access your windows directories you can mount them by using /mnt/<dir>
If you face any issues during installation it is better to use the link I have provided above.
Also note that, the Node installed in the WSL can only be used, iff your working directory is in the WSL or is linked with your WSL(by using mnt).

Bash on Windows (10) doesn't recognize the installed version of node

I have installed Bash on my Windows 10 PC.
Then I downloaded and installed the newest version of node (v6.10.2).
Using the windows command line and typing "node -v" it tells me, that node v.6.10.2 is installed.
Using the Bash command line and again typing "node-v" the output tells me that node v0.10.25 is installed.
How can I get Bash to recognize the new version of node?
Without the new version I cannot download any modules from npm.
You need to find out where is the new Node installed and add it to your PATH in Bash before the place where the old Node is installed.
For example, if your new Node is in /a/b/c/node.exe (is it still exe on Windows?) then you need to do:
export PATH="/a/b/c:$PATH"
in Bash. You should add it to your .profile or .bashrc if you want the change to be persistent.
Keep in mind that you probably need to use the path as recognized in Bash - probably using forward slashes and directories for partitions etc.

Node cli on Msysgit on WIndows 10

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

Resources