npm & node doesn't give any output - node.js

I wanted to install a package via npm, how i already did a few months ago... but somehow i get a response "npm command not found" but i haven't uninstalled it... same with node... whereis node does not show anything aswell... so i installed it again, whereis node outputs node: /usr/bin/node /usr/sbin/node /usr/share/man/man8/node.8.gz /usr/share/man/man1/node.1.gz but it doesn't work... i get no output as seen on the screenshot
please help me fix this probably stupid misstake.

Try re/installing node. NPM comes with node.
$ sudo apt install nodejs
If this is not working, try installing by using NVM (Node Version Manager). NVM is the recommended solution anyway.
https://github.com/nvm-sh/nvm

Related

Homebrew/Node.js showing up though not installed

When I do find . -name "node*" from my root directory, I get:
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node_exporter.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodeenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-sass.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#14.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#10.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodebrew.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#12.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nodenv.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#16.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node-build.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/node#18.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/nodejs
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node#19
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/node.js
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodeclipse.rb
./usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/nodebox.rb
./usr/local/Homebrew/Library/Homebrew/rubocops/cask/extend/node.rb
./usr/local/Homebrew/Library/Homebrew/test/language/node_spec.rb
./usr/local/Homebrew/Library/Homebrew/language/node.rb
but brew ls doesn't show node and node -v and npm show that the commands are not installed on PATH? What's going on here?
I went through the process of
I went through the process of removing all traces of Node and npm from my own installation as npm was corrupted (was mishandling vulnerabilities), and now want to install it using brew, or in some other way so all the errors with npm when attempting to npm install don't occur. Why does brew have node installed even though I didn't install it?
Those files are not NodeJS itself, but are the instructions that tell Homebrew how to install NodeJS. You can remove those formula (along with any others that are not being used) with brew cleanup.
Edit: You cannot actually remove the formulae since those are needed if you were to install it at a later point.

Cant start Node-red

I've tried to install Node-red on Sierra. Used brew to install node and Npm. Then I just followed the instructions on Node-red, but for some reason I can't run Node-red to start it up. I get error message "command not found" ... I've googled like a maniac, without results.
What can I do?
Info:
Osx Sierra 10.13.xx
Node Version 9.11.1
Npm Version 5.6.0
Brew doctor comes out clean.
Brew is updated.
It sounds like the directory that npm links the executables provided by node modules is not on your path.
Try running $(npm get prefix)/bin/node-red in a terminal. If that works, you should add the directory returned by echo $(npm get prefix)/bin/ to your path.
See also: https://superuser.com/questions/1081769/after-npm-install-g-command-still-not-found

What would be the way now to install node with npm via brew

I've installed node on my macOS
brew install node
After doing this, node is installed correctly:
$ node -v
v8.4.0
But running
$ npm -v
gives me -bash: /usr/local/bin/npm: No such file or directory
What would be the way now to install node with npm via brew?
brew install node uses by default --without-npm
I had the same problem. I ran $ brew doctor to make sure node was linked first. Then I ran
$ brew postinstall node
$ npm -v should now show the version number.
I stepped into a similar issue, too. My problem was that I still had not a
~/.bash_profile file in place and therefore no place where to actually link my bash command to npm.
Don't use Homebrew to install node.
I like the Node Version Manager (NVM), and there is n. These are better options on a Mac for node, to avoid certain. issues. later. Plus it avoids this question, as these node versions include npm.
Note, you can install nvm and n via Homebrew. (brew install nvm or brew install n).

NPM Command Not Found After Installing Node

I am having a very hard time getting the npm command to work, and unfortunately my knowledge of unix isn't good enough to solve this on my own. All I've done is brew install node, and I get the following errors:
When I type npm I get zsh: command not found: npm
Looking into this issue more I found this stack overflow answer:
Command not found after npm install in zsh
Following its advice I tried adding export PATH=/usr/local/share/npm/bin:$PATH to my .zshrc file. Still get the same error when typing npm
I can confirm it is in the path echo $PATH yields /Users/nicholashaley/.rbenv/shims:/Users/nicholashaley/.rbenv/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/usr/local/share/npm/bin:/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/usr/local/heroku/bin:/Users/nicholashaley/.rbenv/shims:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
I can also confirm that node has been installed node -v yields v0.12.2
Any ideas? I'm stumped
Not an answer, but maybe a solution...
Uninstall Node via brew: brew uninstall node
Then download Node from https://nodejs.org/en/download/ and install.
npm should then "just work".
I came across to this thread with the same problem but finally below is what worked for me which is without sudo
$ brew update
$ brew uninstall node
$ brew install node
$ chown -R YourUserName /usr/local/lib/node_modules/
$ brew postinstall node #This what the important step
Ok this is what worked for me:
$ brew update
$ brew uninstall node
$ brew install node
$ sudo brew postinstall node #This what the important step
In case this never got solved, this is what worked for me:
brew uninstall node
brew install node
brew doctor and see what needs to be pruned. My problem was there was a non-brew place where I had changed my install location for npm packages because I was trying to get an npm package to install for me. That was a mistake (having forgotten I initially installed node and npm through brew but now brew could no longer reach the npm install directory nor could it change or delete it). So brew prune didn't work even though the symlinks were supposedly deleted but it reminded me that I had changed the npm install location. And that brings us to:
Delete those directories
brew postinstall node
Hope it helps.
I found this article helpful with step-by-step details:
https://www.dyclassroom.com/howto-mac/how-to-install-nodejs-and-npm-on-mac-using-homebrew
Additionally, after all the steps in above article, node was working but my machine was still giving "command not found: npm". I then ran the following two commands and npm was working.
sudo chown -R myusername:myusergroup /usr/local/lib/node_modules
brew postinstall node
Anyone on the LTS release use the following command instead:
brew postinstall node#6
Issue Details in Gist and how I fixed it
1. Installed nodeJs via nvm using Git Bash
2. Installed hyper terminal & WSL
3. Installed Ubuntu (windows Store) & configured zsh shell.
4. Faced the command not found all over in the zsh shell
5. The same commands are working nicely in the bash shell
Tried sourcing the (node, nvm, npm ) paths in the .zshrc and .profile file &
modified the System & Environment Variables in Windows. None of these steps helped me to resolve the issue.
I think the issue is zsh and bash terminals treat things differently. When Installed in bash terminal the default location for the nodeJs in windows will be set to
C:\Users\Program Files\nodejs
The above one is symlinked to C:\Users\<username>\AppData\Roaming\nvm
No matter how much I tried to alias these things in zsh, only node and nvm are working with aliases. npm is failing to locate the necessary lib files.
The only solution that worked for me is Re-installing node in zsh terminal
Removed the node versions installed via nvm in Bash terminal.
Removed the nvm in windows via control Panel
Installed the nvm in the zsh shell
Installed the node latest LTS version from which npm is also installed.
Post Installing the node via nvm in Zsh I observed the following things.
Paths for the node, nvm, npm & npx have been automatically added to the $PATH variable
Node directory is not available neither in C:\Users\Program Files\nodejs
nor the C:\Users\{username}\AppData\Roaming\nvm
Instead it is configured differently at /home/<username>/.nvm/versions/node/v14.15.1/bin/node
This video really helped me in re-installing the node in ZSH: https://www.youtube.com/watch?v=kL8iGErULiw
Usually npm should be found in the same directory as that of the node executable, which can be determined by which node. Check if this directory is part of your PATH. If node was installed through a node version managers such as nodenv and nvm, check the documentation for how to add these executables to the path.
With nodenv, this can be done with:
eval "$(nodenv init -)"

phantomjs version does not seem to be updating

I have been trying to wrap my head around this problem for awhile now. Was hoping if some of you can help shed some light on the issue.
It all started with me wanting to try out https://github.com/metaskills/mocha-phantomjs.
So I followed the instructions and ran
npm install -g mocha-phantomjs phantomjs
Thinking all was well, I wrote my test code and ran
mocha-phantomjs test.js
Here comes my first problem:
mocha-phantomjs requires PhantomJS > 1.9.1
At first it seems simple enough, I probably just need to upgrade the version on phantom. Looked up the latest version and found it to be 1.9.7-1, so I executed:
sudo npm install phantomjs#1.9.7-1 -g
Now here's my second problem:
$ phantomjs -v
gives me
1.8.1
even though I just installed version 1.9.7-1
I did a quick command to verify that I indeed installed 1.9.7-1, I did this in my project folder:
$ npm ls phantomjs
Project#0.0.1 /home/ubuntu/project
└── phantomjs#1.9.7-1 extraneous
Confused, i did a vim on package.json in /usr/lib/node_modules/phantomjs and got this:
"name": "phantomjs",
"version": "1.9.7-1",
"keywords": [
"phantomjs",
"headless",
"webkit"
]
I did a npm -v in the directory /usr/lib/node_modules/phantomjs and i still got 1.8.1.
Assuming it was an installation, i then did this:
npm rm -g phantomjs
Did a reinstallation and its still 1.8.1..
I am completely stumped. Can anyone help shed some light on this?
I had this same issue and it turned out that I had phantomjs installed as a brew package. You can confirm if this is the same for you by running:
brew ls | grep phantomjs
If you do have phantomjs installed as a brew package you can easily uninstall it:
brew uninstall phantomjs
That should fix your problem.
I had the same issue as the author, but the brew command did nothing, as I hadn't installed it via brew. I couldn't remember how i installed it, so this is how i fixed it
first check current version:
phantomjs --version
1.9.0
Find location of installed phantomjs:
which phantomjs
this will tell you where the version of phantomjs is installed so you can remove it. in my case it was installed here:
/usr/local/bin/phantomjs
so remove this directory:
rm -rf /usr/local/bin/phantomjs
this is enough because the phantomjs directory is self containing
then reinstall phantomjs globally (or locally if you just want it local to your project, then you'd need to link the bin/phantomjs executable in your path or in your javascript which is using phantomjs
npm install phantomjs -g
for global install
or
npm install phantomjs --save-dev
for local install
phantomjs --version
1.9.8
Note that this method will probably only help you if you're using or want to use phantomjs via the NPM wrapper: https://github.com/Medium/phantomjs

Resources