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

Package detail

normalize-node-version

ehmicky375.1kApache-2.014.0.1TypeScript support: included

Normalize and validate Node.js versions

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

readme

Node TypeScript Codecov Mastodon Medium

Normalize and validate Node.js versions.

Takes any version range as inputs such as 8, 8.5.0 or >=8 and returns a "major.minor.patch" string. Throws if the Node.js version does not exist.

Example

import normalizeNodeVersion from 'normalize-node-version'

await normalizeNodeVersion('8') // '8.17.0'
await normalizeNodeVersion('8.5.0') // '8.5.0'
await normalizeNodeVersion('v8.5.0') // '8.5.0'
await normalizeNodeVersion('<7') // '6.17.1'
await normalizeNodeVersion('8.5.2') // Error: Invalid Node version
await normalizeNodeVersion('not_a_version') // Error: Invalid Node version

// All available options
await normalizeNodeVersion('8', {
  // Use a mirror for Node.js binaries
  mirror: 'https://npmmirror.com/mirrors/node',
  // Do not cache the list of available Node.js versions
  fetch: true,
  // Cancels when the signal is aborted
  signal: new AbortController().signal,
})

Install

npm install normalize-node-version

This package works in Node.js >=18.18.0.

This is an ES module. It 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.

Usage

normalizeNodeVersion(versionRange, options?)

versionRange: string\ options: object?\ Returns: Promise<string>

options

mirror

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

Base URL to fetch the list of available Node.js versions. 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

signal

Type: AbortSignal

Cancels when the signal is aborted.

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

💻 🎨 🤔 📖

Adrien Becchis

💻 ⚠️ 🤔

Maxim Mazurok

🤔

changelog

14.0.1

Documentation

  • Improve documentation in README.md

14.0.0

Breaking changes

  • Minimal supported Node.js version is now 18.18.0

13.1.0

Features

13.0.0

Breaking changes

  • Minimal supported Node.js version is now 16.17.0

12.4.0

Features

  • Improve tree-shaking support

12.3.0

Features

  • Reduce npm package size by 68%

12.2.0

Features

  • Reduce npm package size

12.1.1

Dependencies

12.1.0

Features

  • Add TypeScript types

12.0.0

Breaking changes

  • Minimal supported Node.js version is now 14.18.0

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

10.0.0

Breaking changes

9.0.1

Dependencies

  • Upgrade all-node-versions

9.0.0

Breaking changes

8.0.1

Dependencies

  • Fix removing core-js

8.0.0

Breaking changes

  • Replace the cache option with the more advanced fetch option

Dependencies

  • Remove core-js

7.1.0

Features

7.0.1

Bug fixes

  • Fix terminal color changing on Windows

7.0.0

Breaking changes

  • Minimal supported Node.js version is now 10.17.0

6.1.2

Bug fixes

  • Fix crash when Node.js binary URL is invalid

6.1.1

Dependencies

  • Upgrade all-node-versions to 4.1.1

6.1.0

Features

  • Use cache when offline (no network connection)

6.0.0

Breaking changes

5.1.1

Dependencies

  • Reduce the number of dependencies

5.1.0

Dependencies

  • Upgrade all-node-versions to 4.1.0

5.0.0

Breaking changes

  • Add the cache option to cache the HTTP request made to retrieve the list of available Node.js versions. This defaults to false.

4.1.4

Bug fixes

  • Fix progress bar jitter.

4.1.3

Internal

  • Improve the appearance of the progress bar (which is not used at the moment)

4.1.2

Bug fixes

  • Fix a bug on non-interactive terminals

4.1.1

Internal

  • Internal changes

4.1.0

Features

  • Improve speed.

4.0.0

Breaking changes

  • Remove the progress option and CLI flags.

3.0.0

Features

2.2.3

Internal

  • Internal changes

2.2.2

Bugs

  • Fix CTRL-C not working

2.2.1

Dependencies

  • Upgrade all-node-versions

2.2.0

Features

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

2.0.1

Bugs

  • Fix cache invalidation bug

2.0.0

Features

  • Retry downloading the Node.js index file on network errors

1.0.1

Internal

  • Internal changes