I've searched the wiki modules page, but I can't find anything similar to virtualenv (python) or rvm.
Anyone here separates node.js in their own env? I really don't like to install npm system-wide.
I've searched the wiki modules page, but I can't find anything similar to virtualenv (python) or rvm.
Anyone here separates node.js in their own env? I really don't like to install npm system-wide.
bxjx's answer is conceptually accurate. However, please note that the bundle command no longer takes a directory. It always drops packages into the
node_modules
folder, so that npm knows where to find them later (and can avoid double-installing dependencies).Any solution will probably involve installing npm and nave "system-wide" (that is, in your
PATH
, which could be in~
somewhere), but then only installing your specific dependencies in the virtual environment.I responded more thoroughly on the github issue.
tl;dr: The use case is valid and helpful, and while it's mostly there, it's not as well served as it could be. We should make sure to think it through and do it right.
There are also some Node version management systems that can help.
Check out Nave https://github.com/isaacs/nave
NVM could also be used https://github.com/creationix/nvm
There is also one called n https://github.com/visionmedia/n
I think it doesn't make sense at all to work on
node
environment without an installed node. It's like you didn't installpython
andpip
when you want to work on apython
project! of course for usingvirtualenv
andirtualenvwrapper
thepre-require
ispython
.If you want to work on a Node project it's really normal to install
node
andnpm
at least.If you just want to run a
python
project on the web (for example withDjango
), you can use the build version of theJavaScript
file and load this file into your project.You don't always need to install dependencies globally. Usually it's recommended because then you can use the commands an npm packages provides, but if you install it locally (in the
node_modules
) directory, you can also use these commands, they only wind up in thenode_modules/.bin/
directory, so you'll have to typenode_modules/.bin/<command>
, which is annoying, but you can of course add this path to yourPATH
environment variable:Then you can just type
<command>
and it works!There's actually an npm command that returns an absolute path to the
.bin
directory:This command also works when you're in a subdirectory of the project, it will return the first
node_modules/.bin
directory it finds in it's parent directories.You can add this alias in your
.bashrc
to automatically add the.bin/
directory to yourPATH
:So when you're in a directory of a project that has a
node_modules/
directory in the root, you can typenodebin
and then you can use all the commands that are in the.bin/
directory!looks there is a better way:
Installing Node.js and npm into a Python Virtualenv
now I can use node tools without mess the global bin environment
nodeenv - virtual environment for node.js ( Analog virtualenv )