nodeenv

Node.js virtual environment

A tool to create isolated node.js environments. Each environment has its own installation directories and doesn't share libraries with other environments. It can also be added to a Python virtualenv.

$ pip install nodeenv

PyPI version CI status Supported Python versions GitHub stars PyPI downloads per month

Quick start

$ nodeenv env $ . env/bin/activate (env) $ node -v (env) $ deactivate_node

On Windows, activate with the script for your shell in env\Scripts: activate.bat for cmd, Activate.ps1 for PowerShell, or activate for git-bash.

Features

Any node version

Choose an exact version, an npm semver range, or lts for the latest LTS release. Ranges also work in a .node-version file. --list shows the available versions.

$ nodeenv --list $ nodeenv --node=22 env $ nodeenv --node=lts env $ nodeenv --node=">=20 <22" env

Reproducible

freeze saves the installed packages to a file. -r, short for --requirements, installs them into a new environment. Add --update to install them into an existing one. .node-version pins node.js itself.

(env) $ freeze reqs.txt (env) $ node -v > .node-version $ nodeenv -r reqs.txt copy

Inside virtualenv

Add node.js to an existing Python virtualenv. Packages installed with npm install -g then go into the virtualenv.

$ . venv/bin/activate (venv) $ nodeenv -p

Prebuilt, mirror or system node.js

--prebuilt
Install node.js from a prebuilt package. This is the default.
--mirror=URL
Download from a mirror of nodejs.org. A file:// URL points at a local directory.
--node=system
Use the system-wide node.js. --prefer-system uses it only when it is found in PATH. Not supported on Windows.

Defaults in ~/.nodeenvrc

Set default values for options in an INI file. The keys are the long option names, written with underscores. With this file nodeenv uses the system-wide node.js when it is found in PATH, and installs the latest LTS release otherwise.

[nodeenv] node = lts prefer_system = True

Read more