Node.js virtual environment builder

1.10.0 · active · verified Sat Mar 28

Nodeenv is a Python tool that facilitates creating isolated Node.js environments, similar to how `virtualenv` manages Python environments. It allows developers to install specific Node.js versions and global npm packages within a dedicated directory, preventing conflicts between different projects. Currently at version 1.10.0, the library maintains an active development pace with several releases per year, incorporating new Python and Node.js version support, as well as bug fixes and improvements like UV virtual environment integration.

Warnings

Install

Quickstart

Nodeenv is primarily a command-line tool. The standard workflow involves setting up a Python virtual environment, installing `nodeenv` into it, and then using `nodeenv` to create a Node.js environment. The `--python-virtualenv` (or `-p`) flag integrates the Node.js environment directly into the currently active Python virtual environment, updating its activation scripts. After installation, reactivating the Python environment or sourcing the `node_env/bin/activate` script ensures the new Node.js environment is active.

# First, create and activate a Python virtual environment
python -m venv my_node_project
source my_node_project/bin/activate

# Install nodeenv into the active Python virtual environment
pip install nodeenv

# Create a Node.js virtual environment within the Python venv, installing a specific Node.js version
# The --python-virtualenv (-p) flag integrates it with the current Python venv
nodeenv --python-virtualenv --node=lts node_env

# Note: nodeenv modifies the activation scripts. Reactivate the Python venv
# or manually source the node_env/bin/activate script.
source my_node_project/bin/activate

# Verify Node.js and npm versions
node -v
npm -v

# Install a global npm package (e.g., `pnpm`)
npm install -g pnpm

# Deactivate the node environment when done
deactivate_node
# Then deactivate the Python virtual environment
deactivate

view raw JSON →