This is small tool will check the engines.node version and uses nvm or n to install the latest version matching the string. If it's a pretty open range like >=18.0.0 for example. It will determine and install node LTS.
$ npm install -g node-package-version
$ npv COMMAND
running command...
$ npv (--version)
node-package-version/0.0.7 darwin-x64 node-v16.20.2
$ npv --help [COMMAND]
USAGE
$ npv COMMAND
...
Fix node version by using nvm or n based on package.json
USAGE
$ npv fix
DESCRIPTION
Fix node version by using nvm or n based on package.json
See code: dist/commands/fix/index.ts
Display help for npv.
USAGE
$ npv help [COMMANDS] [-n]
ARGUMENTS
COMMANDS Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for npv.
See code: @oclif/plugin-help
Just add this code at the end of your .zshrc
file.
precmd(){
npv fix
}
If you go into a new terminal in vscode or cd into a project, it will check the node version and will switch it.