Search code examples
javascriptnode.jsnpmnvm

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.


Solution

  • 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