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:
So using
npm install -g xxxxxwill put the modules in the correct location for NVM but if you try torequireone 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)
require()it.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 runnpm install xxxxxit 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-scriptwhich 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.