Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nve

ehmicky10kApache-2.018.0.1

Run any command on specific Node.js versions

nodejs, node, nvm, npx, versions, versioning, exec, shell, terminal, command-line, cli, dependency-management, es6, javascript, library, npmjs, operating-system, package-manager, server, bash

readme

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ehmicky/design/main/nve/nve_dark.svg"/> nve logo </picture>

Node Codecov Mastodon Medium

Run any command on specific Node.js versions.

Unlike nvm exec it:

  • can run multiple Node.js versions at once
  • can be run programmatically
  • is much faster
  • does not need a separate installation step for each Node version
  • can run the major release's latest minor/patch version automatically
  • works on Windows. No need to run as Administrator.
  • does not require Bash
  • is installed as a Node module (as opposed to a Bash installation script downloaded with curl)

nve executes a single file or command. It does not change the node nor npm global binaries. To run a specific Node.js version for an entire project or shell session, please use nvm, nvm-windows, n or nvs instead.

Hire me

Please reach out if you're looking for a Node.js API or CLI engineer (11 years of experience). Most recently I have been Netlify Build's and Netlify Plugins' technical lead for 2.5 years. I am available for full-time remote positions.

Examples

# Same as `node` but with Node 12
$ nve 12 node
Welcome to Node.js v12.22.12.
Type ".help" for more information.
> .exit

# Same as `node file.js` but with Node 8
$ nve 8 node file.js

# Any command can be used
$ nve 12 npm test

# Execute a local binary
$ nve 8 ava

# Run a specific version
$ nve 8.10.0 npm test

# Use a version range
$ nve "<8" npm test

# Run the latest Node.js version
$ nve latest npm test

# Run the latest LTS version
$ nve lts npm test

# Run the Node version from `~/.nvmrc` or the current process version
$ nve global npm test

# Run the current directory's Node.js version using its `.nvmrc` or `package.json` (`engines.node` field)
$ nve local npm test

# Run the Node version using a file like `.nvmrc` or `package.json`
$ nve /path/to/.nvmrc npm test

# Use a different mirror for the Node binaries
$ nve --mirror=https://npmmirror.com/mirrors/node 8 npm test

# Do not use the cached list of available Node.js versions
$ nve --fetch 8 npm test

# Always use the cached list of available Node.js versions even if it's more
# than one hour old
$ nve --no-fetch 8 npm test

# Use a different CPU architecture for the Node binaries
$ nve --arch=x32 8 npm test

# Chaining commands
$ nve 8 npm run build && nve 8 npm test

# Cache Node 8 download
$ nve 8 node --version

Examples (multiple versions)

# Run multiple versions
$ nve 12,10,8 npm test

 ⬢  Node 12.22.12

  105 tests passed
  Finished 'test' after 3.8 s

 ⬢  Node 10.24.1

  105 tests passed
  Finished 'test' after 4.2 s

 ⬢  Node 8.17.0

  105 tests passed
  Finished 'test' after 4.5 s

# Do not abort on the first version that fails
$ nve --continue 12,10,8 npm test

# Run all versions in parallel
$ nve --parallel 12,10,8 npm test

# Cache multiple Node downloads
$ nve 12,10,8 node --version

Examples (list versions)

# Prints latest Node.js version
$ nve latest
20.4.0

# Prints latest Node.js 8 version
$ nve 8
8.17.0

# Prints latest Node.js 12, 10 and 8 versions
$ nve 12,10,8
12.22.12
10.24.1
8.17.0

Demo

You can try this library:

Install

npm install -g nve

node >=18.18.0 must be globally installed. However the command run by nve can use any Node version (providing it is compatible with it).

To use this programmatically (from Node.js) instead, please check nvexeca.

Usage

nve [OPTIONS...] VERSION,... [COMMAND] [ARGS...]

This is exactly the same as:

COMMAND [ARGS...]

But using a specific Node VERSION. Several comma-separated VERSION can be specified at once.

VERSION can be:

COMMAND must be compatible with the specific Node VERSION. For example npm is only compatible with Node >=6.

Both global and local binaries can be executed.

Options

--continue

Alias: -c\ Type: boolean\ Default: false

By default, when running multiple Node versions and one of those versions fails, the others are aborted. This option disables this.

--parallel

Alias: -p\ Type: boolean\ Default: false

When running multiple Node versions, run all of them at the same time. This is faster. However this does not work if the command:

  • requires some interactive CLI input (for example using a prompt)
  • is not concurrency-safe

--progress

Type: boolean\ Default: true

Whether to show a progress bar while the Node binary is downloading.

--mirror

Alias: -m\ Type: string\ Default: https://nodejs.org/dist

Base URL to retrieve Node binaries. Can be overridden (for example https://npmmirror.com/mirrors/node).

The following environment variables can also be used: NODE_MIRROR, NVM_NODEJS_ORG_MIRROR, N_NODE_MIRROR or NODIST_NODE_MIRROR.

--fetch

Alias: -f\ Type: boolean\ Default: undefined

The list of available Node.js versions is cached for one hour by default. With:

  • --fetch: the cache will not be used
  • --no-fetch: the cache will be used even if it's older than one hour

The default value is undefined (neither of the above). When no COMMAND is specified (only printing the Node.js version), the default value is --fetch instead.

--arch

Alias: -a\ Type: string\ Default: process.arch

Node.js binary's CPU architecture. This is useful for example when you're on x64 but would like to run Node.js x32.

All the values from process.arch are allowed except mips and mipsel.

Initial download

The first time nve is run with a new VERSION, the Node binary is downloaded under the hood. This initially takes few seconds. However subsequent runs are almost instantaneous.

COMMAND can be omitted in order to cache that initial download without executing any commands.

Difference with nvm

nve is meant for one-off command execution. Examples include:

  • running tests with an older Node.js version
  • checking if an older Node.js version supports a specific syntax or feature
  • benchmarking different Node.js versions
  • programmatic usage or child processes

Tools like nvm, nvm-windows, n or nvs are meant to execute a specific Node.js version for an entire machine, project or shell session.

nve can (and probably should) be used alongside those tools.

Native modules

If your code is using native modules, nve works providing:

  • they are built with N-API
  • the target Node.js version is >=8.12.0 (since N-API was not available or stable before that)

Otherwise the following error message is shown: Error: The module was compiled against a different Node.js version.

Benchmarks

The following benchmarks compare the average time to run nve, nvm exec and npx node:

nve:       295ms
nvm exec:  741ms
npx node: 1058ms

See also

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❤️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

Thanks go to our wonderful contributors:

ehmicky
ehmicky

💻 🎨 🤔 📖
Scott Warren
Scott Warren

💬
Charlike Mike Reagent
Charlike Mike Reagent

💬 🤔
Hongarc
Hongarc

🤔
Pedro Augusto de Paula Barbosa
Pedro Augusto de Paula Barbosa

🐛
Adrien Becchis
Adrien Becchis

💻 ⚠️ 🤔
Eric Cornelissen
Eric Cornelissen

🐛 🤔

changelog

18.0.1

Bug fixes

  • Fix EMFILE errors thrown on Windows when nvexeca() is called multiple times at once.

18.0.0

Dependencies

  • Upgrade internal dependencies. This is not expected to be a breaking change.

17.0.0

Breaking changes

  • Minimal supported Node.js version is now 18.18.0

16.1.1

Dependencies

16.1.0

Features

$ nve /path/to/.nvmrc npm test
  • When running multiple Node.js versions, the full resolved versions are now printed. For example, nve 10,12 ... will print Node.js 10.24.1 and Node.js 12.22.12 before each command's output, providing multiple Node.js versions are used at once.

16.0.1

Bug fixes

  • Ensure errors while downloading Node.js binaries are correctly printed (#36)

16.0.0

Breaking changes

  • Minimal supported Node.js version is now 16.17.0

15.5.0

Features

  • Upgrade Execa

15.4.0

Features

  • Reduce npm package size by 41%

15.3.0

Features

  • Improve error handling

15.2.0

Features

  • Reduce npm package size

15.1.0

Features

15.0.0

Breaking changes

  • Minimal supported Node.js version is now 14.18.0

Bug fixes

  • Fix when stdin is empty

14.0.0

Breaking changes

  • Minimal supported Node.js version is now 12.20.0

Features

  • The default value of the --fetch CLI flag is now true when no command was passed.

Bug fixes

  • Fix crash when downloading several Node.js binaries in parallel
  • Improve colors detection
  • Fix offline mode

13.0.0

Breaking changes

  • Commas should now be used to separate multiple Node versions. For example nve 8 10 12 node --version should now be nve 8,10,12 node --version.
  • Rename the alias here to local

Features

  • Add the alias global to target the global Node version, regardless of the current directory

12.0.0

Breaking changes

11.0.0

Breaking changes

  • Aliases c and current renamed to now
  • The alias now now takes into account package.json engines.node field and additional files used by other Node.js version managers.
  • Alias l removed: please use latest instead

Features

  • Added alias lts to target the latest LTS version

10.0.1

Bug fixes

  • Fix aliases shortcuts l and c

10.0.0

Breaking changes

9.3.1

Bug fixes

  • Fix warning message printed when running some commands

9.3.0

Features

Bug fixes

  • Checksum checks were not working when the mirror option was used

9.2.0

Features

9.1.2

Bug fixes

  • Fix terminal color changing on Windows

9.1.1

Bug fixes

9.1.0

Features

9.0.0

Breaking changes

  • Minimal supported Node.js version is now 10.17.0

8.3.0

Features

  • Node.js binary download is now 50% faster on Windows

Bug fixes

  • Fix crash when Node.js binary URL is invalid

8.2.0

Features

  • Node.js binary download is now twice faster on Windows

Bug fixes

  • Fix ARM, PowerPC, S390 support

8.1.0

Features

  • Warn when a new version is available

8.0.3

Bug fixes

  • Fix running npm or npx binaries on Windows

8.0.2

Bug fixes

8.0.1

Bug fixes

  • Fix executing binaries by specifying their file paths on Windows

8.0.0

Breaking changes

  • Remove the --shell CLI flag. Since nve already runs in a shell, this flag is not needed. Shell-specific features (such as variables, globbing, etc.) work as expected since those are performed before nve is called.

7.3.1

Bug fixes

  • Fix executing yarn.

7.3.0

Features

  • Improve the internal directory structure used to cache the Node.js binary
  • Cleanup temporary files when Node.js download fails

Bug fixes

  • Executing npm, yarn and pnpm was not working properly, for example when doing global installs (npm i -g ...).

7.2.0

Features

  • Improve the appearance of the progress bar

7.1.0

Features

  • Ensure Node.js binaries are not corrupted by checking their checksums
  • Use cache when offline (no network connection)

7.0.0

Breaking changes

  • When nve is run without any command, it prints the available Node.js version. If you also want to cache the initial Node.js binary download, you must now use nve VERSION node --version instead of nve VERSION.

Features

  • Make Node.js binary download twice faster on Linux and MacOS
  • Improve error messages

6.1.2

Dependencies

  • Reduce the number of dependencies

6.1.1

Dependencies

  • Reduce the number of dependencies

6.1.0

Dependencies

  • Upgrade nvexeca to 1.1.0

6.0.0

Breaking changes

  • The programmatic API has been moved to a separate repository and npm package nvexeca with fewer dependencies.

5.0.0

Breaking changes

  • The programmatic API has been updated. Please refer to its new documentation.

Features

4.0.1

Internal

  • Internal changes

4.0.0

Features

3.6.0

Features

  • Add the --parallel CLI flag. This allows running multiple Node versions in parallel (at the same time) which is faster.
  • Improve error messages

3.5.0

Features

  • Add the --continue CLI flag. By default, when running multiple Node versions and one of those versions fails, the others are aborted. This flag disables this.

3.4.0

Features

  • Show percentage instead of number of megabytes in spinner

3.3.0

Features

  • Allow running multiple versions at once. For example nve 12 10 8 npm test will run tests on Node 8, 10 and 12.
  • Running multiple versions can also be done programmatically using runVersions()
  • Improve error messages

3.2.2

Bug fixes

  • Fix missing dependency

3.2.1

Dependencies

  • Remove npm-run-path and filter-obj as direct production dependencies

3.2.0

Features

  • Improve speed

3.1.4

Dependencies

  • Remove path-key as a direct production dependency

3.1.3

Dependencies

3.1.2

Internal

  • Internal changes

3.1.1

Bug fixes

3.1.0

Features

  • It is now possible to omit the command. For example nve 8 instead of nve 8 npm test. This can be used to cache the Node.js binary download without executing any command.

3.0.0

Breaking changes

  • nve VERSION must now be followed by node. For example nve 8 should now be nve 8 node and nve 8 file.js should be nve 8 node file.js.
  • The NVE_PROGRESS environment variable has been removed. The --no-progress option should be used instead.
  • The programmatic usage has changed: please see the new API

Features

  • Global binaries can now be executed such as nve 8 npm test. Keep in mind that the binary must be compatible with the chosen Node.js version. For example npm is only compatible with Node >=6.
  • Local binaries can be executed as well
  • Add the --shell option to run a command inside a shell
  • Add the --mirror option to change the base URL to retrieve Node.js binaries
  • Add the --help and --version CLI flags
  • Execa is now used under the hood which provides with additional features and options when run programmatically

Bug fixes

  • If the script spawns child processes, those will now use the correct Node.js version
  • Ensure nve does not exit until stdout and stderr have been flushed

2.2.3

Internal

  • Internal changes

2.2.2

Bug fixes

  • Improve error messages

2.2.1

Bug fixes

  • Fix CTRL-C not working

2.2.0

Features

  • Improve progress messages on console

2.1.0

Features

  • Improve progress messages on console
  • Add alternative names for NODE_MIRROR: NVM_NODEJS_ORG_MIRROR, N_NODE_MIRROR and NODIST_NODE_MIRROR

2.0.1

Bug fixes

  • Fix cache invalidation bug

2.0.0

Features

1.3.0

Features

  • Retry downloading the Node.js binaries on network errors.

1.2.2

Internal

  • Internal changes

1.2.1

Features

  • Spinner can now be disabled with the environment variable NVE_PROGRESS=0

1.2.0

Features

  • A spinner is now shown when a new Node.js version is downloading

1.1.5

Bug fixes