nodeenv
nodeenv
(node.js virtual environment) is a tool to create
isolated node.js environments.
It creates an environment that has its own installation directories, that doesn't share libraries with other node.js virtual environments.
Also new environment can be integrated with environment which was built by virtualenv (python).
Install
Global installation
You can install nodeenv with easy_install:
$ sudo easy_install nodeenv
or pip:
$ sudo pip install nodeenv
Local installation
If you're using virtualenv then you can install nodeenv via
pip
/easy_install
inside any virtual environment built with virtualenv::
$ virtualenv env
$ . env/bin/activate
(env) $ pip install nodeenv
(env) $ nodeenv --version
0.6.5
If you want to work with the latest version of the nodeenv you can install it from the github repository:
$ git clone https://github.com/ekalinin/nodeenv.git
$ ./nodeenv/nodeenv.py --help
Or you can just download raw nodeenv.py and use it::
$ wget https://raw.github.com/ekalinin/nodeenv/master/nodeenv.py
$ python nodeenv.py --version
0.6.5
Usage
Install new environment:
$ nodeenv env
Activate new environment:
$ . env/bin/activate
Chek versions of main packages:
(env) $ node -v
v0.4.6
(env) $ npm -v
0.3.18
Deactivate environment:
(env) $ deactivate_node
Saving into the file versions of all installed packages:
$ . env/bin/activate
(env) $ npm install -g express
(env) $ npm install -g jade
(env) $ freeze ../prod-requirements.txt
Create environment copy from requirement file:
$ nodeenv --requirement=../prod-requirements.txt --jobs=4 env-copy
Requirements files are plain text files that contain a list of packages to be installed. These text files allow you to create repeatable installations. Requirements file example:
$ cat ../prod-requirements.txt
connect@1.3.0
express@2.2.2
jade@0.10.4
mime@1.2.1
npm@0.3.17
qs@0.0.7
If you're already have python virtualenv tool, and want to use nodeenv and virtualenv in conjunction, then you should create (or activate) python virtual environment:
# in case of using virtualenv_wrapper
$ mkvirtualenv my_env
# in cace of using virtualenv
$ . my_env/bin/activate
and add node virtual environment to this existing new_venv:
(my_env) $ nodeenv -p
That's all. Now, all your node.js modules will be installed into your virtual environment:
$ workon my_env
(my_env) $ npm install -g coffee-script
(my_env) $ which coffee
/home/User/virtualenvs/my_env/bin/coffee