nodeenv Documentation

repository·master·Indexed 23 days ago

https://github.com/ekalinin/nodeenv

A tool to create isolated Node.js environments for managing different Node.js and npm versions independently. It supports integration with Python virtual environments via the --python-virtualenv flag, reproducible installations using requirements files, and the ability to install Node.js from prebuilt packages or source.

Tokens
2.1K
Snippets
9
Records
13
Agent score
33%

What's inside nodeenv

  1. Install nodeenv

    master

    You can install nodeenv globally or locally depending on your workflow.

    Global Installation

    Install via pip or easy_install:

    sudo pip install nodeenv

    Local Installation (inside a Python virtualenv)

    If you are already using virtualenv, you can install nodeenv directly into that environment:

    virtualenv env
    . env/bin/activate
    (env) $ pip install nodeenv

    Install from GitHub

    To use the latest version from the source:

    pip install -e git+https://github.com/ekalinin/nodeenv.git#egg=nodeenv
    sudo pip install nodeenv
  2. Integrate Node.js into a Python virtualenv

    master

    If you are using Python's virtualenv or virtualenvwrapper, you can add Node.js to an existing Python environment. This allows Node.js modules to be installed directly into the Python virtual environment.

    1. Create or activate your Python virtual environment (e.g., using mkvirtualenv).
    2. Run nodeenv -p to add Node.js to the active environment.
  3. Create and use a Node.js virtual environment

    master

    Use nodeenv to create isolated Node.js environments with specific versions of Node.js and npm.

    Basic Workflow

    1. Create the environment:
      nodeenv env
    2. Activate the environment:
      . env/bin/activate
    3. Verify versions:
      (env) $ node -v
      (env) $ npm -v
    4. Deactivate when finished:
      (env) $ deactivate_node

    Advanced Creation Options

    • Specific versions: Use --node and --npm flags.
    • From source: Use the --source flag (Unix only).
    • Prebuilt (Default): Uses prebuilt packages for speed. Use --prebuilt to ensure this.
    • Custom Prompt: Use --prompt to change the shell prefix.
    • Without SSL: Use --without-ssl if required.
    • Mirror: Use --mirror=URL to download from a specific mirror.

    Example: Install Node 0.4.3 and npm 0.3.17 with 4 parallel jobs:

    nodeenv --without-ssl --node=0.4.3 --npm=0.3.17 --with-npm --jobs=4 env-4.3
    nodeenv env
    . env/bin/activate
  4. Reproduce environments using requirement files

    master

    You can achieve reproducible installations by using a requirements file. This file contains a list of packages and their specific versions (e.g., package@version).

    To create an exact copy of an environment from a requirements file, use the --requirement flag.

    # Example requirements file content (prod-requirements.txt)
    connect@1.3.0
    express@2.2.2
    npm@0.3.17
    
    # Create an environment from the requirements file
    $ nodeenv --requirement=../prod-requirements.txt --jobs=4 env-copy
  5. Integrate nodeenv with an existing Python virtualenv

    master

    If you are using virtualenv or virtualenv_wrapper, you can add a Node.js environment directly into your existing Python environment using the -p or --python-virtualenv flag.

    Using virtualenv_wrapper

    $ mkvirtualenv my_env
    $ nodeenv -p

    Using virtualenv

    $ . my_env/bin/activate
    $ nodeenv -p

    After running nodeenv -p, your Node.js modules will be installed into the Python virtual environment's directory.

    nodeenv -p
  6. Manage Node.js packages via requirements files

    master

    You can create repeatable installations by using a requirements file containing a list of packages (e.g., connect@1.3.0).

    Create environment from requirements

    nodeenv --requirements=../prod-requirements.txt --jobs=4 env-copy

    Update existing environment from requirements

    To update packages in an active environment without reinstalling Node.js:

    . env-4.3/bin/activate
    (env-4.3)$ nodeenv --requirements=requirements.txt --update env-4.3

    Save current environment state

    To save the versions of currently installed global packages to a file, use the freeze command (part of the environment's bin directory):

    . env-4.3/bin/activate
    (env-4.3)$ npm install -g express
    (env-4.3)$ freeze ../prod-requirements.txt
    nodeenv --requirements=../prod-requirements.txt --jobs=4 env-copy
  7. Create and activate a node.js virtual environment

    master
    To create a new isolated Node.js environment, use the nodeenv command followed by the desired directory name. Once created, activate the environment using the standard activation script located in the bin directory. To exit the environment, use the deactivate_node command.
  8. Install nodeenv globally or locally

    master

    You can install nodeenv globally using pip or easy_install. For local installation within an existing Python virtualenv, activate the environment first and then use pip or easy_install.

    To use the latest development version, you can clone the repository and run the script directly.

    # Global installation
    $ sudo pip install nodeenv
    
    # Local installation in a virtualenv
    $ virtualenv env
    $ . env/bin/activate
    (env) $ pip install nodeenv
    
    # Install from repository
    $ git clone https://github.com/ekalinin/nodeenv.git
    $ ./nodeenv/nodeenv.py --help
  9. Configure nodeenv via .nodeenvrc

    master

    You can use an INI-style file at ~/.nodeenvrc to set default values for many options. The keys in the file should match the long command-line option names.

    Example configuration:

    [nodeenv]
    node = 'latest'
    npm = 'latest'
    with_npm = False
    jobs = '2'
    without_ssl = False
    debug = False
    profile = False
    make = 'make'
    prebuilt = True
    ignore_ssl_certs = False
    mirror = None
    [nodeenv]
    node = 'latest'
    npm = 'latest'
    with_npm = False
    jobs = '2'
    without_ssl = False
    debug = False
    profile = False
    make = 'make'
    prebuilt = True
    ignore_ssl_certs = False
    mirror = None
  10. Run Node.js without activation using shim

    master

    If you want to call node from an environment without manually activating it, use the shim script located in the environment's bin directory.

    Example:

    ./env-4.3/bin/shim --version
    ./env-4.3/bin/shim --version
  11. Configure Node.js installation options

    master

    When creating an environment, you can specify specific versions of Node.js and npm, control SSL support, and set the number of parallel compilation jobs using the following flags:

    • --without-ssl: Install Node.js without SSL support.
    • --node=<version>: Specify the Node.js version.
    • --npm=<version>: Specify the npm version.
    • --jobs=<number>: Set the number of parallel jobs for compilation.
    • --requirement=<file>: Create an environment from a requirements file.
  12. Reference: nodeenv Command Line Options

    master

    Basic Options

    • -n NODE_VER, --node=NODE_VER: The node.js version to use (e.g., --node=22.11.0). Defaults to latest. Use lts for latest LTS or system for system-wide node.
    • -l, --list: Lists available node.js versions.
    • -p, --python-virtualenv: Use current python virtualenv.
    • -r FILENAME, --requirements=FILENAME: Install all packages listed in the given requirements file.
    • --prompt=PROMPT: Provides an alternative prompt prefix.
    • --force: Force installation in a pre-existing directory.
    • --update: Install npm packages from file without reinstalling node.

    Installation Options

    • --prebuilt: Install node.js from prebuilt package (default).
    • --source: Install node.js from the source (Unix only).
    • --mirror=URL: Set mirror server of nodejs.org to download from.
    • -c, --clean-src: Remove "src" directory after installation.

    NPM Options

    • --npm=NPM_VER: The npm version to use (e.g., --npm=10.0.0). Defaults to latest.
    • --with-npm: Install npm into the new virtual environment. Required for node.js < 0.6.3.
    • --no-npm-clean: Skip the npm 0.x cleanup.

    Compilation Options (Unix only)

    • -j JOBS, --jobs=JOBS: Sets number of parallel commands at node.js compilation. Default is 2.
    • --load-average=LOAD: Sets maximum load average for executing parallel commands.
    • -m MAKE_PATH, --make=MAKE_PATH: Path to make command.
    • --without-ssl: Build node.js without SSL support.
    • --debug: Build debug variant of the node.js.
    • --profile: Enable profiling for node.js.

    Other Options

    • -v, --verbose: Verbose mode.
    • -C CONFIG_FILE, --config-file=CONFIG_FILE: Load a different config file than ~/.nodeenvrc.
    • --ignore_ssl_certs: Ignore SSL certificates for package downloads (UNSAFE).
    • --version: Show program version and exit.