Using npm to install packages gives command not found? - node.js

Using npm to install packages, I can never use their cli. For instance, install grunt-cli, avn, nvm, etc. and running
npm install -g avn avn-nvm avn-n
avn setup
Results in command "avn" not found. I don't know if this is a pathing issue, but my PATH is:
/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin:/usr/local/sbin:/usr/local/opt/ruby/bin:/usr/local/lib/python2.7/site-packages:/usr/local/share/npm/bin
I am using OSX.

Your path does not include where the node_modules you're installing globally exist. You need to include the bin path for the modules:
export PATH=$PATH:/usr/lib/node_modules/.bin

Related

Updating NPM with Nodist

I'm unable to update npm, and get it to use with Nodist.
Whenever I try to update npm with the command
npm install -g npm
the following message comes right after executing it:
(node:5304) fs: re-evaluating native module sources is not supported.
If you are using the graceful-fs module, please update it to a more recent version.
C:\Program Files (x86)\Nodist\v\nodev6.5.0\npm -> C:\Program Files (x86)\Nodist\v\nodev6.5.0\node_modules\npm\bin\npm-cli.js
npm#3.10.6 C:\Program Files (x86)\Nodist\v\nodev6.5.0\node_modules\npm
Doing an npm -v right after, gives me the previous version:
...> npm -v
2.14.10
However, if you noticed the last line in the message above, there is npm#3.10.6 which means it is somehow trying to install that version of npm.
I also followed instructions from this post for Ubuntu users and this for Windows users, but they seem to address issues with standalone NodeJS installations and NOT NodeJS + Nodist combo.
Meanwhile, I was wondering if Nodist itself enables us to update npm, or in other words, does it have any version management feature for npm as well, just as it does for node.
Thanks for any help in advance.
Additional Info
I am using Nodist v0.7.1 on Windows 7.
You can try nodist npm latest
Nodist manages npm versions as well as node versions.
Turns out that Nodist versions prior to v0.7.2 have an issue with getting npm set with Nodist correctly (refer the Nodist changelog).
Performing an npm install -g npm was in fact installing the latest version of npm under the v-x64 in Nodist's root installation folder - which is not where Nodist itself looks for npm installation.
Nodist looks for npm inside the \bin folder:
Solution
Add the bin folder's path to your PATH.
cd to the Nodist installation > bin directory with your terminal,
and then perform:
npm install npm
(not with -g flag of course).
Alternatively, if npm install doesn't work in this step, copy an already installed npm and paste it in the node_modules folder within the bin directory.
As a side note, remember to remove some values from your PATH which I suppose may cause conflicts with global package installations (i.e. with -g flag) with npm, before installing Nodist, which are as follows:
%appdata%\npm; OR C:\Users\username\AppData\Roaming\npm;
%ProgramFiles%\nodejs;
I used to have the same issue.
You should use the following command nodist npm 6.14.5, changing the version you need.
And you can see more option whith this command: nodist --help is where I found the answer:
see an example

Global Node Packages Installed to Wrong Directory

I'm trying to install Hexo globally using npm. When I run
npm install -g hexo-cli
I'm informed that it was installed to /Users/myusername/.node/bin/hexo -> /Users/myusername/.node/lib/node_modules/hexo-cli/bin/hexo
The problem comes in when I run hexo init blog and the hexo command is not found.
I installed Node and npm with Homebrew, so when I run which node and which npm, the results are /usr/local/bin/node and /usr/local/bin/npm respectively.
I'm thinking that I still have leftover files and directories from when I installed Node without homebrew, but I don't want to start deleting things without fully knowing the repercussions. Would I be safe to delete all files located in the /Users/myusername/.node/ directory? I can't figure out why npm is not installing to the proper directory.
After a little digging, I found that my npm prefix variable was pointing do the wrong directory, left behind by the old Node installation. I ran npm config get prefix to see where it was pointing.
I set the new prefix value using npm config set prefix /usr/local. Homebrew is symlinked with this directory via /usr/local/bin. I uninstalled hexo-cli and reinstalled through npm, and now it works perfectly.
For NVM users
Run nvm use --delete-prefix v10.13.0 --silent replacing v10.13.0 with whatever version of node you're using.
A simple way to cope with environment variables/path problems on Windows:
Run command:
npm install -g hexo
Using node.js command prompt rather than cmd windows provided by Windows itself.

Using stock node js package installer for OS X, global NPM bower path not recognized

I have installed nodejs with the package installer for OS X, which comes with NPM. The installation for NPM packages seems to be in /Users/victorstan/.node. After successfully installing Bower with npm install -g bower, it fails to let me execute bower:
bower
bash: bower: command not found
How do I get globally installed packages to be properly installed?
Make sure /Users/victorstan/.node/bin is in your PATH. Execute the following command:
echo $PATH
If you can't see that path in the list, you need to add it. Open /Users/victorstan/.bash_profile (or create it if doesn't exist) and add this line:
export PATH=$HOME/.node/bin:$PATH

npm installs all modules in /usr/local/lib/node_modules/

I have node.js 0.8.14 installed on Ubuntu 12.10. I created a directory in my home directory with a sub directory node_modules. I want to install some local node modules there but running
npm install myModule
in this directory installs this module in /usr/local/lib/node_modules/ (same behavior as installing the module with the -g flag
There is no node path in .bashrc.
Any idea how I can install local node modules?
After some further research I found the solution.
Running the command npm config ls revealed that the default config global=false (you see the default config with npm config ls -l) was overwritten by global=true in /home/vsdev/.npmrc and /usr/local/etc/npmrc.
Reverting this to global=false solved the issue.
That is odd.
FYI you don't need to create the node_modules directory, npm will do that for you
npm normally just installs to the current directory. Even if the package you are installing is configured to prefer global installation, npm will install it locally unless you explicitly pass the -g parameter.
can you run the following shell commands and confirm npm is really the real npm?
which npm
alias | grep npm
npm install load all in node_modules then it might be version 3 behaviour http://blog.npmjs.org/post/110924823920/npm-weekly-5 or as mentioned by #vsdev so once you make sure it version 3 behaviour and u want to go with it then its fine else follow below
1- uninstall all modules.. into the node_modules folder in your project then execute: npm uninstall *
2- Tell npm to install with legacy bundling for this one install:
npm install --legacy-bundling
A "permanent" alternative:
Set your npm config to always use legacy bundling...
npm set legacy-bundling=true
.. and run as usual:
npm install
*fetching dependencies with legacy bundling will take a lot more time because many several different versions of the same dependencies will be installed.

Node Version Manager (NVM) npm installing modules to common folder

I've installed NVM for node.js using the instructions from this post:
http://www.backdrifter.com/2011/02/18/using-nvm-and-npm-to-manage-node-js/
When I switch between node versions and then use npm to install a module, all the modules are placed in the same 'node_modules' folder (~/node_modules/) instead of in the 'node_modules' directory specific to that version of node?
Any idea on how to remedy this?
Based on the comments from https://github.com/creationix/nvm/pull/97:
When installing packages with npm using the global switch -g the
package ends up in the proper directory (i.e.
.nvm/$VERSION/lib/node_modules), however node is unable to require it
since it somehow isn't searching on it's prefix.
So using npm install -g xxxxx will put the modules in the correct location for NVM but if you try to require one of them node can't find the module. I am still playing around with this and will update if I find a solution.
Update
Where does NPM put node_modules? (see https://docs.npmjs.com/files/folders)
Local install (default): puts stuff in ./node_modules of the current package root.
Global install (with -g): puts stuff in /usr/local or wherever node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line.
If you need both, then install it in both places, or use npm link.
So what I did was run npm init (see http://npmjs.org/doc/init.html) in my projects root dir which generated package.json. Now when I run npm install xxxxx it creates a node_modules dir in my project folder (which I add to my .gitignore). This works for modules that I require in my code.
For commands such as CoffeeScript I install with npm install -g coffee-script which puts it in the correct directory (.nvm/$VERSION/lib/node_modules). While I can't require these modules (npm link should solve this problem) I can run the commands - i.e. coffee.
I just installed express globally (-g) and was having problem when require("express"). Just like Jesse Vogt said I just reinstalled express but this time without the -g just like this: "sudo npm install express" and now is working perfectly!
For latest nvm window version 1.1.7.
Package was installed and placed into the respective nodejs version.
nvm use 16.8.0
npm install truffle
nvm use 16.7.0
npm install mysql

Resources