Run any command on specific Node.js versions

Overview

Codecov Build Twitter Medium

Run any command on specific Node.js versions.

Unlike nvm exec it:

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.13.0.
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

# 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

# Use a different mirror for the Node binaries
$ nve --mirror=https://npm.taobao.org/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

  105 tests passed
  Finished 'test' after 3.8 s

 ⬢  Node 10

  105 tests passed
  Finished 'test' after 4.2 s

 ⬢  Node 8

  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
13.1.0

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

# Prints latest Node.js 12, 10 and 8 versions
$ nve 12,10,8
12.13.0
10.17.0
8.16.2

Demo

You can try this library:

Install

npm install -g nve

node >=10.17.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 any version range such as 12, 12.6.0 or <12, or one of the following aliases:

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://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.

--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:       199ms
nvm exec: 1002ms
npx node: 1343ms

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

💻 🎨 🤔 📖

Scott Warren

💬

Charlike Mike Reagent

💬 🤔

Hongarc

🤔

Pedro Augusto de Paula Barbosa

🐛

Adrien Becchis

💻 ⚠️ 🤔
Comments
  • Changes in the directory structure of NVE dir(s)

    Changes in the directory structure of NVE dir(s)

    Which problem is this feature request solving?

    Doesn't work with global-dirs and probably other such libraries.

    Describe the solution you'd like

    Currently the node bin is the nve/<VERSION>/node, while it's supposed to be inside a /bin directory inside the version. E.g. nve/12.13.0/bin/node.

    Currently, with NVM

    {
      npm: {
        prefix: '/home/charlike/.nvm/versions/node/v12.13.0',
        packages: '/home/charlike/.nvm/versions/node/v12.13.0/lib/node_modules',
        binaries: '/home/charlike/.nvm/versions/node/v12.13.0/bin'
      }
    }
    

    Currently, with NVE

    {
      npm: {
        prefix: '/home/charlike/.cache/nve',
        packages: '/home/charlike/.cache/nve/lib/node_modules',
        binaries: '/home/charlike/.cache/nve/bin'
      }
    }
    

    The problem comes because global-dirs is doing double path.dirname on process.execPath which for NVE is /home/charlike/.cache/nve/12.13.0/node and that's why we are getting /home/charlike/.cache/nve

    Describe alternatives you've considered

    Alternative would be to go to global-dirs and suggest addition of one if there. But I don't think that is the correct way and place to fix this. Instead, this module should adjust to the convention.

    Can you submit a pull request?

    Yes, probably.

    enhancement 
    opened by tunnckoCore 12
  • Node version aliases interpeted as command

    Node version aliases interpeted as command

    • Bug Description: non whitelisted aliases are interpreted as command

    • Steps to reproduce

      1. install nve@12
      2. run nve 12 default node --version
    • Expected behavior: node version being outpted for node 12, and nvm default node version

    • Current behavior: Crash interpreting default as the command:

       $ nve 10 default node --version
       spawn default ENOENT
      
    • Configuration: none specific

    • Environment:

      System:
        OS: macOS 10.15.4
        CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
        Memory: 3.38 GB / 16.00 GB
        Shell: 5.7.1 - /bin/zsh
      Binaries:
        Node: 10.20.1 - ~/.nvm/versions/node/v10.20.1/bin/node
        Yarn: 1.19.1 - ~/.nvm/versions/node/v8.16.2/bin/yarn
        npm: 6.14.4 - ~/.nvm/versions/node/v10.20.1/bin/npm
      Browsers:
        Chrome: 81.0.4044.113
        Safari: 13.1
      npmGlobalPackages:
        nve: 12.0.0
       
    • Can you submit a pull request?: Yes, but it's better to agree what is best strategy to address the issue.

    • Possible options to solve this problem (probably non exhaustive):

      1. prefix the aliases with some special character, so that they are not interpreted as commands.
        • : could do the trick
        • example: nve 12 :default node --version
      2. use an optional separator to separate versions from commands, something similar to -- with flags
        • : could work too
        • example: nve 12 default : node --version
      3. checking if nve arg is resolvable to a node version or if it's a bash available command

    I would rather go for option 1 or 2. And possibly both as the two command syntax are not incompatible. Tell me what you think about it @ehmicky :)

    enhancement 
    opened by AdrieanKhisbe 10
  • This does not work with global binaries on Windows

    This does not work with global binaries on Windows

    When running global binaries on Windows, the system node is used instead of the one specified by nve:

    $ nve 8 myGlobalBinary
    

    This is because global binaries on Windows are triggered through a shim file (available both as .cmd file or as a Bash script). That shim file is in the same directory as the system node and it explicitly uses it:

    @ECHO off
    SETLOCAL
    CALL :find_dp0
    
    IF EXIST "%dp0%\node.exe" (
      SET "_prog=%dp0%\node.exe"
    ) ELSE (
      SET "_prog=node"
      SET PATHEXT=%PATHEXT:;.JS;=;%
    )
    
    "%_prog%"  "%dp0%\node_modules\myGlobalBinary\build\src\bin.js" %*
    ENDLOCAL
    EXIT /b %errorlevel%
    :find_dp0
    SET dp0=%~dp0
    EXIT /b
    

    In the code above, %dp0%\node.exe explicitly refer to the node.exe in the same directory as the global binary. This bypasses nve which relies on the PATH environment variable.

    bug 
    opened by ehmicky 10
  • npm lifecycle warning to use --scripts-prepend-node-path

    npm lifecycle warning to use --scripts-prepend-node-path

    Hello, first of all thanks for all the work on this :) I have one silly question, sorry to open an issue. This is my setup:

    // run.js
    console.log('process.version', process.version);
    
    $ nve 8 npm start
    npm WARN lifecycle The node binary used for scripts is C:\Users\me\AppData\Local\nve\Cache\8.16.2\node.exe but npm is using C:\Program Files\nodejs\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
    
    > [email protected] start C:\Users\me\Desktop\testing_nve
    > node run.js
    
    process.version v8.16.2
    

    What does the warning shown above by npm really mean?

    npm WARN lifecycle The node binary used for scripts is C:\Users\me\AppData\Local\nve\Cache\8.16.2\node.exe but npm is using C:\Program Files\nodejs\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
    

    Thanks!

    bug 
    opened by papb 10
  • My console text turned green

    My console text turned green

    Describe the bug

    After using nve on windows' command prompt, my console text turned green:

    image

    Steps to reproduce

    I am not sure if this is easy to reproduce, but as shown in the screenshot above I just ran nve --arch=x32 12 node.

    Expected behavior

    nve should not alter the text color :sweat_smile:

    Environment

    • OS: Windows 7 6.1.7601
    • Node: 12.14.1 - C:\NodeJS\node.EXE
    • npm: 6.13.6 - C:\NodeJS\npm.CMD

    Can you submit a pull request?

    No... No time to investigate, sorry...

    bug 
    opened by papb 6
  • Incorrect behaving?

    Incorrect behaving?

    It probably can be fixed with #11.

    Describe the bug

    Not sure exactly if it's a bug. I'm trying to emulate that I'm using nve mainly (like after fresh system install), instead of NVM, to test what some paths will be.

    Steps to reproduce

    I'm on node 12.13 through nvm. I installed, for example pnpm, globally through nve 10 'npm i -g pnpm' and expect to be able to run pnpm through that nve node 10, like nve 10 'pnpm bin --global'. Instead it says that the pnpm command is not found.

    ❯ nve --shell 10 'npm install --global pnpm'
    /home/charlike/.cache/nve/bin/pnpm -> /home/charlike/.cache/nve/lib/node_modules/pnpm/bin/pnpm.js
    /home/charlike/.cache/nve/bin/pnpx -> /home/charlike/.cache/nve/lib/node_modules/pnpm/bin/pnpx.js
    + [email protected]
    updated 1 package in 2.595s
    
    ❯ nve --shell 10 'pnpm bin --global'        
    /bin/sh: pnpm: command not found
    
    ~/github/tunnckoCore/hela next*
    ❯ nve --shell 10 'npm bin --global' 
    /home/charlike/.cache/nve/bin
    (not in PATH env variable)
    

    If I have pnpm installed normally (through nvm, eg. nvm's node/npm) it works, meaning it nve --shell 10 'pnpm bin --global' shows the nvm place of pnpm which is /home/charlike/.nvm/versions/node/v12.13.0/bin

    Expected behavior

    I expect what's installed through nve to be able to be called through nve, and exclusively.

    Current behaving means that if i'm on a fresh machine and just use nve (and put in my shell) as my main daily driver instead of nvm it probably will show/do wrong things.

    Environment

    Enter the following command in a terminal and copy/paste its output:

    Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
    Yarn: 1.17.3 - ~/.nvm/versions/node/v12.13.0/bin/yarn
    npm: 6.13.0 - ~/.nvm/versions/node/v12.13.0/bin/npm
    nve: 7.2.0
    
    bug 
    opened by tunnckoCore 5
  • Question about releases like 4.0.1

    Question about releases like 4.0.1

    Hello :grimacing: sorry for not following the issue template; this is just a question. I watch this repository and noticed that there are a few releases (bumping the patch version) to which your release notes is simply 'internal changes'. What is the point of these releases? (This is not criticism, just a question). When such a release is made, why should a consumer update? How to decide between updating / not updating? From a consumer point of view, nothing changed, right? Thanks for the attention :)

    opened by papb 5
  • Show progress bar downloading

    Show progress bar downloading

    In first time download new node.js version, it is so tedious, just black screen.

    Let user know that nve is downloading node.js(I thought I type wrong command)

    enhancement 
    opened by hong4rc 5
  • Self-contained CLI (package it, no need to have node installed)

    Self-contained CLI (package it, no need to have node installed)

    Because, yes, you usually will have node installed anyway, but I think it will be useful to be able to don't depend on having nodejs. For example, you can package it using pkg or ncc or something like them.

    So in environments that can't/don't have nodejs, they can just download the nve and use it.

    enhancement 
    opened by tunnckoCore 4
  • Bump prismjs from 1.20.0 to 1.21.0

    Bump prismjs from 1.20.0 to 1.21.0

    Bumps prismjs from 1.20.0 to 1.21.0.

    Release notes

    Sourced from prismjs's releases.

    v1.21.0

    Release 1.21.0

    Changelog

    Sourced from prismjs's changelog.

    1.21.0 (2020-08-06)

    New components

    Updated components

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 2
  • Bump minimist from 1.2.5 to 1.2.6

    Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
Releases(15.4.0)
Owner
ehmicky
Node.js back-end developer
ehmicky
Gulp.js command execution for humans

Gulp.js command execution for humans. As opposed to similar plugins or to child_process.exec(), this uses Execa which provides: Better Windows support

ehmicky 55 Dec 14, 2022
Node.js Application Configuration

Configure your Node.js Applications release notes Introduction Node-config organizes hierarchical configurations for your app deployments. It lets you

Loren West 5.9k Jan 4, 2023
simple metadata scrapper for node.js

meta-fetcher Simple metadata scrapper for node.js. Under the hood it uses isomorphic-unfetch to fetch the metadata, parses it and returns it as json o

Rocktim 137 Nov 6, 2022
Node.js object hash library with properties/arrays sorting to provide constant hashes. It also provides a method that returns sorted object strings that can be used for object comparison without hashes.

node-object-hash Tiny and fast node.js object hash library with properties/arrays sorting to provide constant hashes. It also provides a method that r

Alexander 73 Oct 7, 2022
Node.js CLI tool to visualize an aggregate list of your dependencies' licenses

licenseye Node.js CLI tool to visualize an aggregate list of your project's dependencies' licenses. Install Yarn yarn global add licenseye NPM npm ins

Liran Tal 36 Dec 21, 2022
Abstracts execution of tasks in parallel using Node.js cluster.

cluster-map Abstracts execution of tasks in parallel using Node.js cluster. It is a high level abstraction around a common pattern used to delegate a

Gajus Kuizinas 27 Jul 3, 2022
Clock and task scheduler for node.js applications, providing extensive control of time and callback scheduling in prod and test code

#zeit A node.js clock and scheduler, intended to take place of the global V8 object for manipulation of time and task scheduling which would be handle

David Denton 12 Dec 21, 2021
Run a command, watch the filesystem, stop the process on file change and then run the command again...

hubmon Run a command, watch the filesystem, stop the process on file change and then run the command again... Install You can install this command lin

Hubert SABLONNIÈRE 7 Jul 30, 2022
A complete media query framework for CSS, to apply specific properties in specific screen

A complete media query framework for CSS, to apply specific properties in specific screen Note: Size of every media query is `50px, 100px, 150px, 200p

Rohit Chouhan 6 Aug 23, 2022
Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troubleshooting

nvm.sh 63.8k Jan 9, 2023
Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region

Run Any Node.js Version in AWS Lambda Everynode allows you to run any version of Node.js in AWS Lambda, in any commercial AWS region. We add support f

Fusebit 116 Dec 15, 2022
A jQuery plugin that creates a paneled-style menu (like the type seen in the mobile versions of Facebook and Google, as well as in many native iPhone applications).

#jPanelMenu ###Version 1.4.1 jPanelMenu is a jQuery plugin for easily creating and managing off-canvas content. Check out the demo (and documentation)

Anthony Colangelo 927 Dec 14, 2022
Fallback for SVG images by automatically creating PNG versions on-the-fly

SVGMagic - Cross browser SVG This repository is no longer actively mainted. It has proven to be very usefull back in 2013, but these days SVGs are sup

Dirk Groenen 596 Jul 27, 2022
caniuse.com but for PHP - a searchable list of new and deprecated features in recent PHP versions

caniphp.com caniphp.com is like caniuse.com but for PHP features. It's a simple search of PHP features that added, deprecated and removed in recent ve

Ross Wintle 95 Dec 25, 2022
🚀 Blazing fast thread channels integration for all Discord.js versions

djs-threads ?? Blazing fast thread integration for all Discord.js versions ?? THIS PROJECT IS ARCHIVED this project is archived because Discord will c

SpongeBed 4 Feb 28, 2022
🪵 Aggressively find a packages changelog (or releases) between versions.

?? changelogd Aggressively find a packages changelog (or releases) between versions. Status: Early Access Please report any issues ?? Made possible by

Harlan Wilton 8 May 10, 2022
Minimal versions of popular analytics libraries. Reduce the impact of third-party scripts on your application.

minimal-analytics This project aims to provide minimal implementations of popular analytics libraries. It's aimed at users who want to reduce the impa

James Hill 32 Dec 25, 2022
A full documentation on everything we know about Alpha 1.0.16 versions.

Minecraft's Alpha 1.0.16 Versions Before you start, make sure to watch RetroGamingNow's video about this first. Highly influenced (technically a port

_NexTre_ 44 Dec 23, 2022
logs ROBLOX's updates and new versions

roblox-update-notifier logs ROBLOX's updates and new versions This is meant to be ran in NodeJS, 24/7, using something like pm2. NPM packages required

null 5 Oct 23, 2022