Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

get-node

ehmicky75.6kApache-2.015.0.4TypeScript support: included

Download a specific version of Node.js

nodejs, node, download, nvm, npx, versions, versioning, exec, shell, terminal, command-line, cli, dependency-management, es6, javascript, typescript, library, npmjs, operating-system, package-manager

readme

Node TypeScript Codecov Mastodon Medium

Download a specific version of Node.js.

The Node.js release is downloaded, uncompressed and untared to an executable file ready to run.

Features

Fast:

  • the download is cached
  • the best compression algorithm available on your machine is used
  • everything is streamed

Reliable:

  • the binary is checked against official checksums
  • can be safely run concurrently
  • atomic writes

Features include:

Example

import getNode from 'get-node'

// Download a specific Node.js release
const { path, version } = await getNode('8')
console.log(path) // /home/user/.cache/nve/8.17.0/node
console.log(version) // 8.17.0
// Download Node.js latest release
const { path, version } = await getNode('latest')
console.log(path) // /home/user/.cache/nve/16.3.0/node
console.log(version) // 16.3.0
// Any version range can be used
await getNode('8.12.0')
await getNode('<7')
// Download latest LTS Node.js version
await getNode('lts')
// Download Node.js version from `~/.nvmrc` or the current process version
await getNode('global')
// Download current directory's Node.js version using its `.nvmrc` or
// `package.json` (`engines.node` field)
await getNode('local')
// Download Node.js version from a specific file like `.nvmrc` or `package.json`
await getNode('/path/to/.nvmrc')
// Specify the output directory
const { path } = await getNode('8', {
  output: '/home/user/.cache/node_releases/',
})
console.log(path) // /home/user/.cache/node_releases/13.0.1/node
// Use a mirror website
await getNode('8', { mirror: 'https://npmmirror.com/mirrors/node' })
// Specify the CPU architecture
await getNode('8', { arch: 'x32' })

Install

npm install get-node

node >=18.18.0 must be globally installed. However any Node version can be downloaded.

This package is an ES module and must be loaded using an import or import() statement, not require(). If TypeScript is used, it must be configured to output ES modules, not CommonJS.

To use this module as a CLI instead, please check get-node-cli.

Usage

getNode(versionRange, options?)

versionRange: string\ options: object?\ Return value: Promise<object>

versionRange can be:

Options

output

Type: string\ Default: global cache directory such as /home/user/.cache/nve/.

Output directory for the node executable.

It the directory already has a node executable, no download is performed. This enables caching.

progress

Type: boolean\ Default: false

Whether to show a progress bar.

mirror

Type: string\ Default: https://nodejs.org/dist

Base URL to retrieve Node.js binaries. Can be customized (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

Type: boolean\ Default: undefined

The list of available Node.js versions is cached for one hour by default. If the fetch option is:

  • true: the cache will not be used
  • false: the cache will be used even if it's older than one hour

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.

cwd

Type: string | URL\ Default: .

When using the local alias, start looking for a Node.js version file from this directory.

signal

Type: AbortSignal

Cancels when the signal is aborted.

Return value

The returned Promise resolves to an object with the following properties.

path

Type: string

Absolute path to the node executable.

version

Type: string

Normalized Node.js version.

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

💻 🎨 🤔 📖

Charlike Mike Reagent

🐛

hiroki osame

💻 ⚠️ 🤔

changelog

15.0.4

Dependencies

  • Upgrade tar-fs dependency

15.0.3

Documentation

  • Improve documentation in README.md

15.0.2

Security fix

  • Fix vulnerability in tar-fs dependency by upgrading it

15.0.1

Dependencies

15.0.0

Breaking changes

  • Minimal supported Node.js version is now 18.18.0

14.2.1

Dependencies

14.2.0

Features

const { path, version } = await getNode('/path/to/.nvmrc')

14.1.0

Features

14.0.0

Breaking changes

  • Minimal supported Node.js version is now 16.17.0

13.6.0

Features

  • Upgrade Execa

13.5.0

Features

  • Improve tree-shaking support

13.4.0

Features

  • Reduce npm package size by 53%

13.3.0

Features

  • Reduce npm package size

13.2.0

Features

  • Reduce npm package size

13.1.0

Features

  • Improve TypeScript types

13.0.1

Dependencies

  • Upgrade node-version-alias

13.0.0

Breaking changes

  • Minimal supported Node.js version is now 14.18.0

Features

12.1.0

Features

  • Add TypeScript types.

12.0.0

Breaking changes

  • Minimal supported Node.js version is now 12.20.0
  • This package is now an ES module. It can only be loaded with an import or import() statement, not require(). See this post for more information.

11.0.2

Bug fixes

  • Fix issue with SIGINT handlers

11.0.1

Bug fixes

  • Fix crash when downloading several Node.js binaries in parallel

11.0.0

Breaking changes

Features

  • Add the alias global to target the global Node version, regardless of the current directory

10.0.0

Breaking changes

9.0.0

Breaking changes

  • Aliases c and current renamed to now
  • The alias now now takes into account package.json engines.node field and additional files used by other Node.js version managers.
  • Alias l removed: please use latest instead

Features

  • Added alias lts to target the latest LTS version

8.0.1

Bug fixes

  • Fix aliases shortcuts l and c

8.0.0

Breaking changes

7.3.1

Dependencies

  • Fix removing core-js

7.3.0

Features

Bug fixes

  • Checksum checks were not working when the mirror option was used

Dependencies

  • Remove core-js

7.2.2

Bug fixes

  • Fix cwd option

7.2.1

Bug fixes

  • Fix _ and . aliases not working

7.2.0

Features

7.1.2

Bug fixes

  • Fix terminal color changing on Windows

7.1.1

Bug fixes

7.1.0

Features

7.0.0

Breaking changes

  • Minimal supported Node.js version is now 10.17.0

6.6.0

Features

  • Node.js binary download is now 50% faster on Windows

Bug fixes

  • Fix crash when Node.js binary URL is invalid

6.5.0

Features

  • Node.js binary download is now twice faster on Windows

Bug fixes

  • Fix ARM, PowerPC, S390 support

6.4.0

Features

  • Improve the internal directory structure used to cache the Node.js binary
  • Cleanup temporary files when Node.js download fails

6.3.0

Features

  • Improve the appearance of the progress bar

6.2.0

Features

  • Ensure Node.js binaries are not corrupted by checking their checksums
  • Use cache when offline (no network connection)

6.1.0

Features

  • Make Node.js binary download twice faster on Linux and MacOS
  • Improve error messages

Bug fixes

  • Fix downloading Node.js 0.12 and below on Windows

6.0.1

Dependencies

  • Reduce the number of dependencies

6.0.0

Breaking changes

  • Separate the CLI into its own repository and npm package get-node-cli to reduce the number of dependencies.

5.5.0

Dependencies

  • Upgrade fetch-node-website to 4.0.0
  • Upgrade normalize-node-version to 5.1.0

5.4.1

Bug fixes

  • Fix progress bar jitter.

5.4.0

Features

5.3.0

Features

5.2.0

Features

  • Show percentage instead of number of megabytes in spinner

5.1.0

Features

  • Improve speed

5.0.0

Breaking changes

4.0.3

Internal

  • Internal changes

4.0.2

Bugs

  • Improve error messages

4.0.1

Bugs

  • Fix CTRL-C not working

4.0.0

Breaking changes

  • The output directory is now specified as an --output flag instead of a positional argument on the CLI. This means get-node VERSION OUTPUT should now be get-node --output=OUTPUT VERSION.

Features

  • Add --help and --version CLI flags
  • Add --progress CLI flag
  • Add --mirror option
  • Improve CLI spinner

Bugs

  • Fix error messages not printed correctly (50128cd)

3.1.0

Features

  • Improve progress messages on console
  • Add alternative names for NODE_MIRROR: NVM_NODEJS_ORG_MIRROR, N_NODE_MIRROR and NODIST_NODE_MIRROR

3.0.1

Bugs

  • Fix cache invalidation bug

3.0.0

Breaking changes

  • The output directory now defaults to a global cache directory instead of the current directory.

Features

  • The Node.js/programmatic API is now documented and exposed

2.0.1

Internal

  • Internal changes

2.0.0

Features

  • Retry downloading the Node.js binaries on network errors

1.1.0

Features

  • A spinner is now shown when a new Node.js version is downloading