- Notifications
You must be signed in to change notification settings - Fork15
Run any command on specific Node.js versions
License
ehmicky/nve
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Run any command on specific Node.js versions.
Unlikenvm exec
it:
- can runmultiple Node.js versions at once
- can be runprogrammatically
- ismuch 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 aBash installation scriptdownloaded with
curl
)
nve
executes asingle file or command. It does not change thenode
nornpm
global binaries. To run a specific Node.js version for anentire projector shell session, please usenvm
,nvm-windows
,n
ornvs
instead.
Pleasereach outif you're looking for a Node.js API or CLI engineer (11 years of experience).Most recently I have beenNetlify Build'sandNetlify Plugins'technical lead for 2.5 years. I am available for full-time remote positions.
# Same as `node` but with Node 12$ nve 12 nodeWelcome 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 npmtest# Execute a local binary$ nve 8 ava# Run a specific version$ nve 8.10.0 npmtest# Use a version range$ nve"<8" npmtest# Run the latest Node.js version$ nve latest npmtest# Run the latest LTS version$ nve lts npmtest# Run the Node version from `~/.nvmrc` or the current process version$ nve global npmtest# Run the current directory's Node.js version using its `.nvmrc` or `package.json` (`engines.node` field)$ nvelocal npmtest# Run the Node version using a file like `.nvmrc` or `package.json`$ nve /path/to/.nvmrc npmtest# Use a different mirror for the Node binaries$ nve --mirror=https://npmmirror.com/mirrors/node 8 npmtest# Do not use the cached list of available Node.js versions$ nve --fetch 8 npmtest# Always use the cached list of available Node.js versions even if it's more# than one hour old$ nve --no-fetch 8 npmtest# Use a different CPU architecture for the Node binaries$ nve --arch=x32 8 npmtest# Chaining commands$ nve 8 npm run build&& nve 8 npmtest# Cache Node 8 download$ nve 8 node --version
# Run multiple versions$ nve 12,10,8 npmtest ⬢ 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 npmtest# Run all versions in parallel$ nve --parallel 12,10,8 npmtest# Cache multiple Node downloads$ nve 12,10,8 node --version
# Prints latest Node.js version$ nve latest20.4.0# Prints latest Node.js 8 version$ nve 88.17.0# Prints latest Node.js 12, 10 and 8 versions$ nve 12,10,812.22.1210.24.18.17.0
npm install -g nve
node >=18.18.0
must be globally installed. However the command run bynve
can use any Node version (providing it is compatible with it).
To use this programmatically (from Node.js) instead, please checknvexeca
.
nve [OPTIONS...] VERSION,... [COMMAND] [ARGS...]
This is exactly the same as:
COMMAND [ARGS...]
But using a specific NodeVERSION
. Several comma-separatedVERSION
can bespecified at once.
VERSION
can be:
- anyversion range such as
12
,12.6.0
or<12
latest
: Latest available Node versionlts
: Latest LTS Node versionglobal
: Global Node version- Using the home directory
.nvmrc
orpackage.json
(engines.node
field) - Some similar filesused by other Node.js version managers are also searched for
- If nothing is found, defaults to the current process's Node version
- Using the home directory
local
: Current directory's Node version- Using the current directory or parent directories
.nvmrc
,package.json
(engines.node
field)orsimilar files - Defaults to the
global
version
- Using the current directory or parent directories
- a file path towards a
.nvmrc
,package.json
(engines.node
field)orsimilar files
COMMAND
must be compatible with the specific NodeVERSION
. For examplenpm
isonly compatible with Node>=6
.
Both global and local binaries can be executed.
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.
Alias:-p
Type:boolean
Default:false
When running multiple Node versions, run all of them at the same time. This isfaster. However this does not work if the command:
- requires some interactive CLI input (for example using a prompt)
- is not concurrency-safe
Type:boolean
Default:true
Whether to show a progress bar while the Node binary is downloading.
Alias:-m
Type:string
Default:https://nodejs.org/dist
Base URL to retrieve Node binaries. Can be overridden (for examplehttps://npmmirror.com/mirrors/node
).
The following environment variables can also be used:NODE_MIRROR
,NVM_NODEJS_ORG_MIRROR
,N_NODE_MIRROR
orNODIST_NODE_MIRROR
.
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 isundefined
(neither of the above). When noCOMMAND
isspecified (only printing the Node.js version), the default value is--fetch
instead.
Alias:-a
Type:string
Default:process.arch
Node.js binary's CPU architecture. This is useful for example when you're on x64but would like to run Node.js x32.
All the values fromprocess.arch
areallowed exceptmips
andmipsel
.
The first timenve
is run with a newVERSION
, the Node binary is downloadedunder the hood. This initially takes few seconds. However subsequent runs arealmost instantaneous.
COMMAND
can be omitted in order to cache that initial download withoutexecuting any commands.
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 likenvm
,nvm-windows
,n
ornvs
aremeant to execute a specific Node.js version for an entire machine, project orshell session.
nve
can (and probably should) be used alongside those tools.
If your code is using native modules,nve
works providing:
- they are built withN-API
- the target Node.js version is
>=8.12.0
(since N-API was not available orstable before that)
Otherwise the following error message is shown:Error: The module was compiled against a different Node.js version
.
Thefollowing benchmarks compare the average time to runnve
,nvm exec
andnpx node
:
nve: 295msnvm exec: 741msnpx node: 1058ms
nvexeca
: Likenve
but programmatic(from Node.js)execa
: Process execution for humansget-node
: Download Node.jspreferred-node-version
:Get the preferred Node.js version of a project or usernode-version-alias
: ResolveNode.js version aliases likelatest
,lts
orerbium
normalize-node-version
:Normalize and validate Node.js versionsall-node-versions
: List allavailable Node.js versionsfetch-node-website
: Fetchreleases on nodejs.orgglobal-cache-dir
: Get theglobal cache directory
For any question,don't hesitate tosubmit an issue on GitHub.
Everyone is welcome regardless of personal background. We enforce aCode of conduct in order to promote a positive andinclusive environment.
This project was made with ❤️. The simplest way to give back is by starring andsharing it online.
If the documentation is unclear or has a typo, please click on the page'sEdit
button (pencil icon) and suggest a correction.
If you would like to help us fix a bug or add a new feature, please check ourguidelines. Pull requests are welcome!
Thanks go to our wonderful contributors:
ehmicky 💻🎨🤔📖 | Scott Warren 💬 | Charlike Mike Reagent 💬🤔 | Hongarc 🤔 | Pedro Augusto de Paula Barbosa 🐛 | Adrien Becchis 💻 | Eric Cornelissen 🐛🤔 |
About
Run any command on specific Node.js versions