Popularity
4.1
Growing
Activity
9.4
Growing
478
7
9

Description

This executes a file, command or REPL using a specific Node.js version.

Unlike `nvm run` it:

- is 10 times faster

- does not need a separate installation step for each Node version

- works on Windows

- does not require Bash

- is installed as a Node module (as opposed to a Bash installation script downloaded with curl)

Monthly Downloads: 0
Programming language: JavaScript
Tags: Nodejs     Utilities     Command Line Utilities     JavaScript     CLI     Version    
Latest version: v3.2.2

nve alternatives and similar modules

Based on the "Command Line Utilities" category

Do you think we are missing an alternative of nve or a related project?

Add another 'Command Line Utilities' Module

README

Codecov Travis Gitter Twitter Medium

Run any Node.js version.

This executes any command using a specific Node.js version.

Unlike nvm exec it:

  • can be run programmatically
  • is 10 times faster
  • does not need a separate installation step for each Node version
  • always runs the latest minor/patch Node version (unless explicitly specified)
  • 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.

Examples

# Same as `node` but with Node 12
$ nve 12 node
Welcome to Node.js v12.11.1.
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 8 npm test

# Execute a local binary
$ nve 8 ava

# Run a specific version
$ nve 8.10.0 npm test

# Run the latest Node version
$ nve "*" npm test

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

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

# Chaining commands without a shell
$ nve 8 npm run build && nve 8 npm test
# Chaining commands with a shell
$ nve --shell 8 "npm run build && npm test"

# Cache Node 8 download without executing any command
$ nve 8

Programmatically:

<!-- Remove 'eslint-skip' once estree supports top-level await --> <!-- eslint-skip -->

const { runVersion } = require('nve')

const { childProcess, version } = await runVersion('8', 'node', ['--version'])
console.log(version) // 8.16.1
const { exitCode, stdout, stderr } = await childProcess
console.log(exitCode) // 0
console.log(stdout) // v8.16.1

Demo

You can try this library:

  • either directly in your browser.
  • or by executing the [examples files](examples/README.md) in a terminal.

Install

npm install -g nve

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

Usage

CLI

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

This is exactly the same as:

COMMAND [ARGS...]

But using a specific Node VERSION.

VERSION can be any version range such as 12, 12.6.0 or <12.

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.

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.

Options

--shell

Alias: -s Type: booleanDefault: false

When using shell-specific chaining or structures such as && or ||, nve should be repeated.

nve 8 npm run build && nve 8 npm test

Although not recommended, --shell can achieve the same result by running the command inside a shell.

nve --shell 8 "npm run build && npm test"

Please note that shell-specific features such as globbing, environment variables or $VARIABLE expansion work even without --shell.

--progress

Type: booleanDefault: true

Whether to show a progress spinner when the Node binary is downloading.

--mirror

Alias: -mType: stringDefault: https://nodejs.org/dist

Base URL to retrieve Node binaries. Can be overridden (for example https://npm.taobao.org/mirrors/node).

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

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.

Programmatic

runVersion(versionRange, command?, args?, options?)

versionRange: string command: stringargs: string[] options: objectReturn value: Promise<object>

command and args are the same as in execa(command, args, options)

Options

progress

Like the [--progress CLI option](#--progress). Defaults to false.

mirror

Like the [--mirror CLI option](#--mirror).

spawnOptions

Type: objectDefault: {}

Options passed to execa(command, args, options)

The preferLocal option is always true.

Return value

Type: Promise<object>

childProcess

Type: execaResult?

childProcess instance. It is also a Promise resolving or rejecting with a childProcessResult.

This is undefined when command is undefined.

version

Type: string

Normalized Node.js version. For example if v8 was passed as input, version will be "8.16.1".

Example

<!-- Remove 'eslint-skip' once estree supports top-level await --> <!-- eslint-skip -->

const { runVersion } = require('nve')

const { childProcess, version } = await runVersion(
  '8',
  'command',
  ['--version'],
  options,
)
const { exitCode, stdout, stderr } = await childProcess

Benchmarks

The [following benchmarks](benchmarks/main.js) compare the average time to run nve, nvm exec and npx node:

nve:       106ms
nvm exec: 1020ms
npx node: 1437ms

See also

Support

If you found a bug or would like a new feature, don't hesitate to [submit an issue on GitHub](../../issues).

For other questions, feel free to chat with us on Gitter.

Everyone is welcome regardless of personal background. We enforce a [Code of conduct](CODE_OF_CONDUCT.md) 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](CONTRIBUTING.md). Pull requests are welcome!

Thanks go to our wonderful contributors:

<!-- ALL-CONTRIBUTORS-LIST:START --> <!-- prettier-ignore --> ehmicky💻 🎨 🤔 📖 Scott Warren💬 Charlike Mike Reagent💬 🤔 Hongarc🤔

<!-- ALL-CONTRIBUTORS-LIST:END -->