← All tools

ehmicky/normalize-node-version

Popularity 65 Updated Development & Build

Normalize and validate Node.js versions

githubauto-collected

Installation

A directly usable install command is not verified yet. Check the project documentation or releases.

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

// 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](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),
not `require()`. If TypeScript is used, it must be configured to
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),
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: NODEMIRROR, NVMNODEJSORGMIRROR, NNODEMIRROR or NODISTNODEMIRROR.

#### 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