Git Product home page Git Product logo

nvexeca's Introduction

Codecov Build Gitter Twitter Medium

nvm + execa = nvexeca.

Execa improves child processes execution with a promise interface, cross-platform support, local binaries, interleaved output, and more.

nvexeca is a thin wrapper around Execa to run any file or command using any Node.js version.

Unlike nvm exec it:

  • is run programmatically
  • does not need a separate installation step for each Node version
  • can run the major release's latest minor/patch version automatically
  • does not require Bash
  • is installed as a Node module
  • works on Windows. No need to run as Administrator.

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

Example

const nvexeca = require('nvexeca')

const { childProcess, versionRange, version } = await nvexeca('8', 'node', [
  '--version',
])
console.log(`Node ${versionRange} (${version})`) // Node 8 (8.16.2)
const { exitCode, stdout, stderr } = await childProcess
console.log(`Exit code: ${exitCode}`) // 0
console.log(stdout) // v8.16.2

Install

npm install nvexeca

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

To use this as a CLI instead, please check nve.

Usage

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

versionRange: string
command: string
args: string[]?
options: object?
Return value: Promise<object>

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

command is the file or command to execute. args are the arguments passed to it.

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

Both global and local binaries can be executed.

Options

Type: object

All Execa options are available. Please refer to Execa for the list of possible options.

The preferLocal option is always true.

The following options are also available.

dry

Type: boolean
Default: false

Do not execute the command. This can be used to cache the initial Node.js binary download.

progress

Type: boolean
Default: false

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

mirror

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.

arch

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.

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 the dry option is true.

versionRange

Type: string

Node.js version passed as input, such as "v10".

version

Type: string

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

command

Type: string

File or command that was executed.

args

Type: string[]

Arguments that were passed to the command.

execaOptions

Type: object

Options that were passed to Execa.

Initial download

The first time nvexeca 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.

Native modules

If your code is using native modules, nvexeca 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.

See also

Support

If you found a bug or would like a new feature, don't hesitate to submit an issue on GitHub.

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

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!

ehmicky
ehmicky

๐Ÿ’ป ๐ŸŽจ ๐Ÿค” ๐Ÿ“–

nvexeca's People

Contributors

ehmicky avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.