NPM -bash command not found - node.js

I am trying to run through nodeschool.io exercises. I am having trouble running their packages.
The first package I installed:
$ npm install -g learnyounode
$ learnyounode
Runs the package with the command learnyounode
Every other package on their site I tried installing and can't run the program with the proper command in the command line, ex:
$ npm install -g functional-javascript-workshop#latest
$ /Users/name/npm/bin/functional-javascript -> /Users/name/npm/lib/node_modules/functional-javascript-workshop/functional-javascript.js
/Users/name/npm/bin/functional-javascript-workshop -> /Users/name/npm/lib/node_modules/functional-javascript-workshop/functional-javascript.js
functional-javascript-workshop#0.0.27 /Users/name/npm/lib/node_modules/functional-javascript-workshop
├── lorem-ipsum#0.1.1 (inflection#1.2.7, optimist#0.3.7)
└── workshopper#0.7.2 (map-async#0.1.1, tuple-stream#0.0.2, split#0.2.10, through#2.3.6, mkdirp#0.3.5, colors-tmpl#0.1.0, xtend#2.1.2, terminal-menu#0.2.0, optimist#0.6.1, msee#0.1.1)
$ functional-javascript-workshop
$ -bash: functional-javascript-workshop: command not found
Here is a link to the package I am trying to install in the example: functional-javascript-workshop
As you can see, I am getting the message
-bash - command not found
Looking at other posts with similar problems, I ran the following commands to see my path and where the packages are being saved:
$ which node
$ /usr/local/bin/node
$ which npm
$ /usr/local/bin/npm
$PATH
$ Users/name/.rbenv/shims:/Users/name/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin: No such file or directory
Steps I tried:
Uninstall/Reinstall node using brew commands
global update npm's ($ npm update -g)
It looks like my node-modules are being installed at /Users/name/npm/lib/node_modules I'm not sure though how to give my command line access or a way of looking into that path for the command to start the program.

The functional-javascript-workshop executable is in /Users/name/npm/bin, which is not in your PATH variable, add this to your .bashrc or .bash_profile file:
export PATH=$PATH:/Users/name/npm/bin
Then you should be able to run functional-javascript-workshop

Related

Even though http-server and angular-http-server installed, get "bash: http-server: command not found"

I tried use the current ways around stackoverflow but still get bash: http-server: command not found
also th npm list -g http-server returns:
pi#raspberrypi:/usr/local/lib/node_modules $ npm list -g http-server
/usr/local/lib
└── (empty)
and the echo $PATH returns followed result based on .bashrc file:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/.npm-global/bin:/usr/.npm-global/bin:/usr/local/lib/node_modules
Additionaly I install it with this command sudo npm install http-serve -g which can see its output as below:
/root/.npm-global/bin/http-serve -> /root/.npm-global/lib/node_modules/http-serve/bin/http-serve
/root/.npm-global/bin/hs -> /root/.npm-global/lib/node_modules/http-serve/bin/http-serve
+ http-serve#1.0.1
added 21 packages from 25 contributors in 13.863s
Switch to your current user by using '-'. This way all the references will be copied. Usually, this error is also given when references are missing.
Also, try to give the full path of the command.

Install for #angular/cli not working on Mac

I'm trying to setup Angular 2 using "npm install #angular/cli -g "
After the install, the only warning I see is the UNMET PEER DEPENDENCY rxjs#^5.0.1, which I then install and reinstall "npm install #angular/cli -g"
No matter what I do, or what version of Node I setup with n, I keep getting the following message when trying to user the "ng" commands:
zsh: command not found: ng
I've been looking around and have not found a solution for this.
Has anyone run into this and have any suggestions?
UPDATE:
It looks like this is not a angular/cli specific issue.
I now see that I get the same message when I try to run "Grunt" and "Ionic" commands on an existing project that was working fine.
zsh: command not found: ionic
zsh: command not found: grunt
Most likely, the directory in which the global modules are installed is not in your $PATH -- and therefore unknown to your shell.
To fix this issue, we can create a new directory for global node_modules, configure npm to use it, and add that directory to your $PATH.
# create a new directory where npm will install packages
$ mkdir ~/.node_modules
# set npm "prefix" config to that directory
$ npm config set prefix '~/.node_modules'
# append a line to your .zshrc instructing it to include that directory in your $PATH, making the executables known to the shell
$ echo 'export PATH=~/.node_modules/bin:$PATH' >> ~/.zshrc
# update current shell with new path (not needed for new sessions)
$ source ~/.zshrc
Then, first reinstall the latest npm (npm i -g npm), followed by the global packages you need (npm i -g #angular/cli).
For more on PATH, see this definition: http://www.linfo.org/path_env_var.html

Installing NPM package globally does not create bash command

I've tried to install http-server. It installs fine. Here's the output:
$ npm install -g http-server
/Users/jonrojas/.npm-packages/bin/http-server -> /Users/jonrojas/.npm-packages/lib/node_modules/http-server/bin/http-server
/Users/jonrojas/.npm-packages/bin/hs -> /Users/jonrojas/.npm-packages/lib/node_modules/http-server/bin/http-server
/Users/jonrojas/.npm-packages/lib
└── http-server#0.9.0
As soon as I try to run hs, I get:
-bash: hs: command not found
When I try npm config get prefix, I receive:
/Users/jonrojas/.npm-packages
How would I update my .bashrc file to get this working? (or other steps?)
To note: this isn't specific to http-server. I also tried to install another package that has a bash command, but it also did not work.

npm command not found error but node is installed

I installed node and npm with Homebrew a while ago, they both worked fine until today when I keep running into the npm command not found error.
When is run $ whereis node, I get nothing back
When I do $ which node, I see /usr/local/bin/node
When I do $ node -v, I see v4.4.7
When I do $ whereis npm, I get nothing back
When I do $ which npm, I get nothing back
When I do $ npm -v, I see -bash: npm: command not found
I have tried
$ brew update
$ brew uninstall npm
$ brew install npm
I have also made sure that my $NODE_PATH environment variable is set:
# In ~/.bash_profile file:
export NODE_PATH="/usr/local/lib/node_modules"
I also followed these instructions from https://himanen.info/solved-npm-command-not-found/
Nothing seems to work and I keep getting npm: command not found when I run any command in any folder with npm. Any ideas? Thanks
I had the same issue, I am using a MAC.
It was a permission issue in my case, here is what I already did:
$ brew update
$ brew uninstall npm
$ brew install npm
That didn't work for me, so I tried this:
$ sudo chmod -R 777 /usr/local/lib
$ brew postinstall node
and this linked installed node with npm, when I typed:
$ npm -v
5.3.0
Now all commands followed by NPM are working fine,
like npm install
Hope this will work for all!!
Figured out the issue. So the root of the problem was that I installed npm using Homebrew and there are some issues with what goes on under the hood with Homebrew and npm.
To fix this I did the following:
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
Important!
Do this in .bash_profile
export PATH="$HOME/.npm-packages/bin:$PATH"
export PATH="$HOME/.node/bin:$PATH"
Now everything works like a charm
In mac via homebrew, when you are getting error like
Error: Permission denied # dir_s_mkdir - /usr/local/lib/node_modules/npm
or mostly getting several folder permission, don't give full permission like
$ sudo chmod -R 777 /usr/local/lib
Please use as mentioned below
$ sudo chown -R $(whoami):admin /usr/local/lib/node_modules/
What it will do, simply gives the ownership to the user (linux users also can use this).
Hint: And in mac please use homebrew for installation. Advantages of homebrew you can switch between versions, easy to uninstall, you no need to run as root (sudo), like wise lots of advantages are there, as a developer its recommended to use homebrew (https://brew.sh/). And one more thing whenever you are getting some error like permission denied or something don't, give the full permission instead of using chmod use chown.
I had the same issue, I executed following command to install node and npm - it worked perfectly.
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node

Npm not working after Mavericks update

My npm in terminal isn't working after Mavericks update.
node app.js works well and runs my app, but when I run npm followed by anything I get -bash: npm: command not found. I know this question has been asked before here:
Global installation with npm doesn't work after Mac OS X Mavericks update
and
How do I install a module globally using npm?
and npm not working after reinstalling Mac OS X
, but none of the answers resolved my situation.
$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/mongodb/bin
How did you install node.js ? typically it comes bundled with both node and npm, where both are in the same directory. My suggestion is to remove your current install(s) and do the following with just works.
to install nodejs and npm as yourself NOT root do these commands (OSX/linux) :
parent_dir=${HOME}/bin_xxxx # replace bin_xxx with something specific
# to node release like bin_v0.10.31
mkdir ${parent_dir}
download source from : http://nodejs.org/download/
cd node-v0.xxxx
./configure --prefix=${parent_dir}/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${parent_dir}/nodejs/bin:$PATH
define environment variable NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${parent_dir}/nodejs/lib/node_modules
do above AND use syntax : npm install -g some_cool_module
always use the -g for global so it gets installed into dir $NODE_PATH
and not your $PWD
nodejs install gives you npm as well :
ls -la ${parent_dir}/nodejs/bin
For Debian, after installing node do following
curl -k -O -L https://npmjs.org/install.sh
ln -s /usr/bin/nodejs /usr/bin/node
sh install.sh

Resources