Installing NPM package globally does not create bash command - node.js

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.

Related

Nodemon installed but can't be found

I've tried uninstalling and and reinstalling nodemon several times both locally and globally with:
npm install -g nodemon
(tried it both with and without sudo)
and it seems to install no problem, and gives me:
/usr/local/bin/bin/nodemon -> /usr/local/bin/lib/node_modules/nodemon/bin/nodemon.js
/usr/local/bin/lib
└── nodemon#1.11.0
but whenever I run
nodemon server.js
in my app, I get;
-bash: nodemon: command not found
Like I mentioned, I've tried the same process but installing locally to my app dependancies, but it doesn't seem to make a difference. What's going on here? I followed the same process on a different machine, and it worked no problem.
Googling around, I came across some posts that mentioned changing/adding the PATH? But it's not clear to me if that's or the problem or what that means.
Also, other globally installed npm modules run just fine
nodemon is not being found by bash.
Edit your ~/.bash_profile file and add:
PATH=$PATH:/usr/local/bin/bin/
Start a new shell to see it work, or run source ~/.bash_profile to have it apply to the current session.
Instead of using sudo switched as root and then just run:
$ npm install -g nodemon
sudo su -
export PATH=$PATH:/home/USER/npm
npm install -g --force nodemon
# THESE LINES + START FROM A NEW TERMINAL...
# IN MY CASE
npm install -g --force node-inspector
# TOO

Node command not found

I'm trying to install avrgirl-arduino using the command sudo npm install avrgirl-arduino. When I try running the command avrgirl-arduino list I get an error saying -bash: avrgirl-arduino: command not found. I ran npm init before running the first command and it still doesn't work.
You may want to install your package globally :
npm install -g avrgirl-arduino
This way you can use command line tool package (like grunt)

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

NPM -bash command not found

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

node npm local install puts files into ~/node_modules

When I install a package using npm install command, it installs the files into ~/node_modules. When I run the package, I get command not found error.
How do I install it into a folder where I want to call the package?
npm install <name_of_package> -g
This will install the package globally. If the program is in your PATH, then you should be able to run it just like any other program.
For example:
npm install nodemon -g
then run nodemon from the command prompt, and it should work
If you don't want to install it globally, the right answer is the last comment in the checked answer:
Simply add ./node_modules/.bin to your PATH, and all the commands installed locally by npm will be available. – H_I Dec 24 '12 at 9:54
You can add it to your path in your .bashrc file using the command:
export PATH="$PATH:/home/login/node_modules/.bin"
Reload your .bashrc using:
source .bashrc

Resources