npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-version-call-local

v1.1.1

Published

Call a function in a Node version found in PATH

Downloads

16,166

Readme

node-version-call-local

Call a function in a Node version found in PATH.

This is a lightweight alternative to node-version-call that finds an existing Node in PATH rather than installing one. Use this when you need to execute code in a different Node version without the overhead of installation dependencies.

Installation

npm install node-version-call-local

Usage

Sync API (returns value, throws on error)

import { callSync, bindSync } from 'node-version-call-local';

// Immediate call - returns value synchronously
const result = callSync('>0.12', '/path/to/worker.js', {}, arg1, arg2);

// Bound caller for repeated use
const worker = bindSync('>0.12', '/path/to/worker.js', {});
const result1 = worker(arg1);
const result2 = worker(arg2);

Async API (callback or Promise)

import call, { bind } from 'node-version-call-local';

// With callback (last argument is function)
call('>0.12', '/path/to/worker.js', {}, arg1, (err, result) => {
  if (err) return console.error(err);
  console.log(result);
});

// With Promise (no callback)
const result = await call('>0.12', '/path/to/worker.js', {}, arg1);

// Bound caller with callback
const worker = bind('>0.12', '/path/to/worker.js', {});
worker(arg1, (err, result) => { /* ... */ });

// Bound caller with Promise
const result = await worker(arg1);

API

Sync Functions

callSync(version, workerPath, options?, ...args)

Execute a file synchronously in a Node version found in PATH.

  • version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')
  • workerPath - Path to the file to execute
  • options - Execution options (see below)
  • args - Arguments to pass to the worker

Returns the result from the worker. Throws on error.

bindSync(version, workerPath, options?)

Create a bound caller for repeated synchronous use.

Returns a function (...args) => result that calls the worker.

Async Functions

call(version, workerPath, options?, ...args)

Execute a file asynchronously in a Node version found in PATH.

  • If last argument is a function, it's treated as a callback: (err, result) => void
  • Otherwise, returns a Promise

bind(version, workerPath, options?)

Create a bound caller for repeated async use.

Returns a function that:

  • Takes a callback as last arg: (...args, callback) => void
  • Or returns a Promise: (...args) => Promise<result>

Options

interface CallOptions {
  callbacks?: boolean;      // Worker uses callback style (default: false)
  spawnOptions?: boolean;   // Use spawnOptions for child process env setup (default: true)
  env?: NodeJS.ProcessEnv;  // Environment variables (default: process.env)
}
  • callbacks - Set to true if the worker function uses callback style (fn(...args, callback)) rather than returning a value or Promise
  • spawnOptions - When true, sets up proper environment (PATH, etc.) so child processes spawned by the worker use the correct Node version
  • env - Custom environment variables to pass to the worker

Comparison with node-version-call

| Feature | node-version-call-local | node-version-call | |---------|---------------------------|-------------------| | Version not found | Throws error | Installs it | | Dependencies | Lightweight | Heavy (install chain) | | Version binding | At bind time | At call time | | Use case | Polyfills, bootstrap code | Testing, exact versions |

Example: HTTPS polyfill for old Node

import { callSync } from 'node-version-call-local';

const major = +process.versions.node.split('.')[0];
const noHTTPS = major === 0;

function fetchFileSync(url) {
  if (noHTTPS) {
    // Current Node can't do HTTPS, find one that can
    return callSync('>0', __filename, {}, url);
  }
  // Modern Node - fetch directly
  return fetchSync(url);
}

Example: Async with Promise

import call from 'node-version-call-local';

async function fetchData(url) {
  // Worker uses callback style internally
  const result = await call('>10', '/path/to/worker.js', { callbacks: true }, url);
  return result;
}

Example: npm install polyfill

import { bindSync } from 'node-version-call-local';

const major = +process.versions.node.split('.')[0];

// Worker that runs npm install
const workerPath = path.join(__dirname, 'workers', 'npmInstall.js');

// Need spawnOptions for npm environment
const npmInstall = bindSync('>10', workerPath, { spawnOptions: true });

function install(packageName) {
  if (major > 10) {
    // Current Node is fine
    return runNpmInstall(packageName);
  }
  // Use older Node found in PATH
  return npmInstall(packageName);
}

License

MIT