Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - Configuring $NODE_PATH with NVM

On my way setting up Node.js with NVM, I stumbled upon an error when using Yeoman. I got the error

Cannot find module 'yeoman-generator'

After some research I found this post on StackOverflow, which is also about my problem. Now I tried to do so, but the problem I have is, that I want to use different versions of Node.js over the system with the use of NVM. Now is it possible to change the $NODE_PATH dynamically, if the Node.js version changes with the help of NVM? Because my $NODE_PATH is empty at the moment (this is causing the problem).

$ which node
/Users/dschmidt/.nvm/v0.10.35/bin/node
$ which npm
/Users/dschmidt/.nvm/v0.10.35/bin/npm
$ echo $NODE_PATH
[empty]

Would be glad about every answer I get about this. I searched the web for this, but could not find one post about this specifically.

like image 840
Nick Schmidt Avatar asked Jan 10 '15 13:01

Nick Schmidt


2 Answers

Adding following to .bashrc or .zshrc helps

export NODE_PATH=$NODE_PATH:`npm root -g`

I am not expert whether that is good.

source as pointed out by Pensierinmusica

like image 143
jethar Avatar answered Oct 20 '22 16:10

jethar


NVM will set the path for node and npm once you run

nvm use <node_version>

However, that is just for the current shell and any new shells will not have a version of node an npm selected until your run the previous command unless you set a default version

nvm alias default <node_version>

voila! You have a working version of npm and node in any new shell you open.

To change the default simply run it again with the new version of node you want to use. e.g.

nvm alias default v5.4.0
like image 27
Kosmonaut Avatar answered Oct 20 '22 18:10

Kosmonaut