Node.js virtual environment builder
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
- breaking Version 1.7.0 of `nodeenv` dropped support for Python versions 3.4, 3.5, and 3.6. Users on these Python versions must either upgrade their Python environment or pin `nodeenv` to a version older than 1.7.0.
- gotcha When using `nodeenv --python-virtualenv` (or `-p`) to integrate Node.js into a Python virtual environment, ensure your Python virtual environment is active. Running the command without an active Python venv will result in a 'no python virtualenv is available' error, even if `nodeenv` itself is installed.
- gotcha Using the `--ignore_ssl_certs` option can bypass SSL certificate verification, which poses a security risk. This option should only be used in trusted environments and with full understanding of the implications.
- gotcha Initial `nodeenv` installation or Node.js compilation can appear to hang without output, especially on slower connections or when compiling from source. This is often due to large downloads or long compilation times.
Install
-
pip install nodeenv
Quickstart
# 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