• Stars
    star
    614
  • Rank 73,061 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run any command on specific Node.js versions
nve logo

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:      261ms
nvm exec: 619ms
npx node: 994ms

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

🐛 🤔

More Repositories

1

cross-platform-node-guide

📗 How to write cross-platform Node.js code
JavaScript
1,331
star
2

modern-errors

Handle errors in a simple, stable, consistent way
JavaScript
1,273
star
3

wild-wild-path

🤠 Object property paths with wildcards and regexps 🌵
JavaScript
608
star
4

log-process-errors

Show some ❤️ to Node.js process errors
JavaScript
471
star
5

human-signals

Human-friendly process signals
JavaScript
261
star
6

autoserver

Create a full-featured REST/GraphQL API from a configuration file
JavaScript
200
star
7

safe-json-value

⛑️ JSON serialization should never fail
JavaScript
198
star
8

cross-platform-terminal-characters

All the characters that work on most terminals
JavaScript
196
star
9

unix-permissions

Swiss Army knife for Unix permissions
JavaScript
119
star
10

test-each

🤖 Repeat tests. Repeat tests. Repeat tests.
JavaScript
103
star
11

Notes

Technologies I've learned
sed
58
star
12

gulp-execa

Gulp.js command execution for humans
JavaScript
55
star
13

fast-cartesian

Fast cartesian product
TypeScript
53
star
14

get-bin-path

Get the current package's binary path
JavaScript
34
star
15

wild-wild-utils

🤠 Functional utilities using object property paths with wildcards and regexps 🌵
JavaScript
28
star
16

get-node

Download a specific version of Node.js
JavaScript
19
star
17

handle-cli-error

💣 Error handler for CLI applications 💥
JavaScript
15
star
18

keep-func-props

Wrap a function without changing its name and other properties
JavaScript
13
star
19

node-version-alias

Resolve Node.js version aliases like `latest`, `lts` or `erbium`
JavaScript
12
star
20

big-cartesian

Cartesian product for big inputs
TypeScript
12
star
21

eslint-config

ESLint configuration for my own projects
JavaScript
10
star
22

preferred-node-version

Get the preferred Node.js version of a project or user
JavaScript
9
star
23

all-node-versions

List all available Node.js versions
JavaScript
9
star
24

error-serializer

Convert errors to/from plain objects.
JavaScript
9
star
25

modern-errors-http

`modern-errors` plugin to create HTTP error responses.
TypeScript
8
star
26

normalize-node-version

Normalize and validate Node.js versions
JavaScript
8
star
27

cv-website

Static page with my CV website
HTML
8
star
28

truncate-json

Truncate a JSON string.
JavaScript
8
star
29

merge-error-cause

Merge an error with its `cause`
JavaScript
7
star
30

get-node-cli

Download a specific version of Node.js (CLI)
JavaScript
7
star
31

global-cache-dir

Get the global cache directory
JavaScript
6
star
32

dev-tasks

Automated development tasks for my own projects
Shell
5
star
33

modern-errors-serialize

`modern-errors` plugin to serialize/parse errors.
JavaScript
5
star
34

portuguese-conjugation-cheat-sheet

Portuguese conjugation cheat sheet
CSS
5
star
35

spyd

Complete yet simple benchmark runner
JavaScript
5
star
36

string-byte-length

Get the UTF-8 byte length of a string.
JavaScript
5
star
37

template-javascript

JavaScript library template
JavaScript
5
star
38

colors-option

Let users toggle colors
JavaScript
5
star
39

modern-errors-winston

`modern-errors` plugin for Winston.
JavaScript
5
star
40

normalize-exception

Normalize exceptions/errors
JavaScript
5
star
41

abstract-parser

Abstraction layer for JavaScript parsers
JavaScript
4
star
42

modern-errors-cli

`modern-errors` plugin to handle errors in CLI modules.
TypeScript
4
star
43

error-custom-class

Create custom error classes
JavaScript
4
star
44

fetch-node-website

Fetch releases on nodejs.org
JavaScript
4
star
45

winston-error-format

Log errors with Winston
JavaScript
4
star
46

is-json-value

Check if a value is valid JSON.
JavaScript
4
star
47

error-cause-polyfill

Polyfill `error.cause`
JavaScript
4
star
48

modern-errors-switch

`modern-errors` plugin to execute class-specific logic.
JavaScript
4
star
49

modern-errors-clean

`modern-errors` plugin to clean stack traces.
JavaScript
4
star
50

wild-wild-parser

🤠 Parser for object property paths with wildcards and regexps 🌵
JavaScript
4
star
51

precise-now

Like `performance.now()` but in nanoseconds
TypeScript
4
star
52

error-http-response

Create HTTP error responses.
JavaScript
3
star
53

test-api

[WIP] Automated API testing
JavaScript
3
star
54

modern-errors-process

`modern-errors` plugin to handle process errors.
JavaScript
3
star
55

guess-json-indent

Guess the indentation of a JSON string.
JavaScript
3
star
56

time-resolution

Find the process's time resolution
TypeScript
3
star
57

is-error-instance

Check if a value is an `Error` instance.
TypeScript
3
star
58

declarative-merge

Merge objects/arrays declaratively
JavaScript
3
star
59

template-typescript

TypeScript library template
TypeScript
3
star
60

modern-errors-bugs

`modern-errors` plugin to print where to report bugs.
JavaScript
3
star
61

set-error-class

Properly update an error's class.
JavaScript
2
star
62

dev-parser

Parse JavaScript using a terminal
JavaScript
2
star
63

ehmicky

Node.js back-end developer
2
star
64

set-error-stack

Properly update an error's stack.
JavaScript
2
star
65

set-array

Set array items declaratively
JavaScript
2
star
66

set-error-message

Properly update an error's message.
JavaScript
2
star
67

set-error-props

Properly update an error's properties
JavaScript
2
star
68

string-byte-slice

Like `string.slice()` but bytewise.
JavaScript
2
star
69

redefine-property

Better `Object.defineProperty()`
JavaScript
2
star
70

terminal-theme

🎨 Use a color theme for your code's terminal output
JavaScript
2
star
71

wrap-error-message

Properly wrap an error's message.
JavaScript
2
star
72

chalk-string

Chalk with style strings.
JavaScript
2
star
73

error-class-utils

Properly create error classes.
JavaScript
2
star
74

create-error-types

Create multiple error types.
JavaScript
1
star
75

oh-oh

This is an.
JavaScript
1
star
76

design

Logos of my projects
1
star
77

prettier-config

Prettier configuration for my own projects
JavaScript
1
star