wanted-node-version

Detects which version of Node your program should be using, by looking at .nvmrc, .node-version and the engines.node field of package.json.

Usage no npm install needed!

<script type="module">
  import wantedNodeVersion from 'https://cdn.skypack.dev/wanted-node-version';
</script>

README

wanted-node-version

Detects which version of Node your program should be using, by looking at .nvmrc, .node-version and the engines.node field of package.json.

Installation

npm install wanted-node-version --save

Usage

const wantedNodeVersion = require('wanted-node-version');

const versionInfo = wantedNodeVersion(process.cwd());

console.log(versionInfo);

Outputs:

{ sources:
   { '.nvmrc': '8',
     '.node-version': '9.0.0',
     'engines.node': '>=8' },
  version: '8',
  conflict: true }
  • The sources property is an object that contains the version-range that was set for each source.
  • The version property is a string containing the wanted node version-version from the first of nvmrc, node-version, engines.node (in that order).
  • The conflict property tells you if all version ranges found are in conflict (true) or not (false).

See also

To further deal with version-range strings, I recommend using the excellent semver module.

License

MIT