I am totally new to Node.js. Can anyone tell me if there is anything similar to Python's virtualenv
? I need to run apps on different versions of Node.js on the same machine.
Check out nvm by Tim Caswell, it's a version manager for Node.js. It allows you to install multiple version of Node.js in parallel, and also manages version-independent variants of the global module cache for you. With nvm it basically comes down to:
$ nvm install 0.10.24
$ nvm use 0.10.24
And then you have Node.js 0.10.24 up and running, including the appropriate version of npm.
Installation of nvm is as easy as running a simple shell command:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
Another option may be n by TJ Holowaychuk or nave by Isaac Z. Schlueter, although I don't have any experience with either of them.
Basically, they work quite similar to nvm. Installing n is as easy as running a shell script, too:
$ make install
Afterwards you are able to type:
$ n 0.10.24
$ n
Then you can select which installed version you'd like to use. From what I've heard n works better than nvm if you are on Windows.
nave is a shell script, again, and its usage is similar to that of nvm:
$ nave install 0.10.24
$ nave use 0.10.24
And that's it :-)!
I remember that in Python - it comes down to using pythonbrew
for switching between multiple versions of Python installed on the system (for example 2.7 and 3.0). For this - Node.js analogy would be in using nvm install
as described by Golo.
When it comes to per project package management - in Python you would use virtualenv
or virtualenvwrapper
(even better) to organize modules and specific versions for your project. In Node.js this is assumed (that every project has own dependencies) - and you specify this in package.json
file.
When you execute npm install
all your packages are downloaded and installed in root_dir/.node_modules/ directory (which is local to project, assuming that root_dir is root of your Node project).
However, you can still install packages globally for node by using this command:
npm install -g "package_name"
General rule would be this:
If you’re installing something that you want to use in your program, using require('whatever')
, then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH
environment variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With