Node.js Wheel Binaries

24.14.1 · active · verified Thu Apr 09

The `nodejs-wheel-binaries` library provides unofficial Node.js and npm binaries packaged as a Python wheel. This allows Python projects to easily access and execute Node.js without requiring a system-wide Node.js installation, particularly useful in isolated or CI/CD environments. The current version is 24.14.1, and it typically releases new versions corresponding to major Node.js updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to locate the Node.js and npm executables provided by the package and then execute simple commands using `subprocess`. This is the primary way to interact with Node.js via this library.

import subprocess
from nodejs_wheel_binaries import find_nodejs_bin, find_npm_bin

# Find the Node.js executable
node_bin = find_nodejs_bin()
npm_bin = find_npm_bin()

if node_bin:
    print(f"Node.js binary found at: {node_bin}")
    try:
        # Run a simple Node.js command to get its version
        result = subprocess.run([node_bin, '--version'], capture_output=True, text=True, check=True)
        print(f"Node.js version: {result.stdout.strip()}")

        # Example: Run a simple JS script directly
        js_code = "console.log('Hello from Node.js via Python!');"
        result = subprocess.run([node_bin, '-e', js_code], capture_output=True, text=True, check=True)
        print(f"Node.js script output: {result.stdout.strip()}")

    except FileNotFoundError:
        print("Node.js executable not found in PATH after discovery.")
    except subprocess.CalledProcessError as e:
        print(f"Error running Node.js command: {e}")
        print(f"Stderr: {e.stderr}")
else:
    print("Node.js binary could not be found by the wheel.")

if npm_bin:
    print(f"\nNPM binary found at: {npm_bin}")
    try:
        # Run a simple NPM command to get its version
        result = subprocess.run([npm_bin, '--version'], capture_output=True, text=True, check=True)
        print(f"NPM version: {result.stdout.strip()}")
    except subprocess.CalledProcessError as e:
        print(f"Error running NPM command: {e}")
        print(f"Stderr: {e.stderr}")

view raw JSON →