A tool similar to virtualenv, used to set a specific node version for a specified project, which is used to meet the needs of different node versions of different projects.
It is similar to nvm, but not a replacement for nvm. nvm manages the global node version for you, and can even switch node versions temporarily.
virtual-node-env can also switch node versions, but not globally, but following the project.
Note
In actual project development, you may encounter situations where several projects depend on different node versions. For example 12.x.y / 16.x.y / 20.x.y.
They are not fully compatible, so you need node version management tools, such as nvm. And it requires manual version switching, not automatic. In my project, there are some automatic CIs, so the node version needs to automatically follow the project.
- Cross-platform supports. including windows
- Automatically download node
- Support
use
command to switch node version temporarily
# Start a new shell with the specified node version
$ virtual-node-env use 16.20.0
$ node -v
16.20.0
# Specify the node version and run the specified command
$ virtual-node-env use 18.20.0 node -v
v18.20.0
or put it into package.json
npm install @axetroy/virtual-node-env --save-exact -D
"scripts": {
"install-deps": "virtual-node-env use 16.20.0 npm install",
"build": "virtual-node-env use 16.20.0 npm build"
},
more usage, please run virtual-node-env --help
$ virtual-node-env --help
virtual-node-env - Virtual node environment, similar to nvm
USAGE:
virtual-node-env [OPTIONS] use <VERSION> [COMMAND]
virtual-node-env [OPTIONS] clean
virtual-node-env [OPTIONS] ls|list
virtual-node-env [OPTIONS] ls-remote|list-remote
COMMANDS:
use <VERSION> [COMMAND] Use the specified version of node to run the command
clean Clean the virtual node environment
ls|list List all the installed node version
ls-remote|list-remote List all the available node version
OPTIONS:
--help Print help information
--version Print version information
--config Specify the configuration file. Detected .virtual-node-env.json automatically if not specified.
ENVIRONMENT VARIABLES:
NODE_MIRROR The mirror of the nodejs download, defaults to: https://nodejs.org/dist/
Chinese users defaults to: https://registry.npmmirror.com/-/binary/node/
NODE_ENV_DIR The directory where the nodejs is stored, defaults to: $HOME/.virtual-node-env
DEBUG Print debug information when set DEBUG=1
SOURCE CODE:
https://github.com/axetroy/virtual-node-env
- Install via Cask (Mac/Linux/Windows)
$ cask install github.com/axetroy/virtual-node-env
$ virtual-node-env --help
- Install via npm
$ npm install @axetroy/virtual-node-env -g
$ virtual-node-env --help
$ virtual-node-env clean
# then remove the binary file
Your can specify the configuration file by --config
option, or put a .virtual-node-env.json
file in the root of your project.
{
"node": "v16.20.0"
}
then you can run virtual-node-env
without specify the version
$ virtual-node-env node -v
v16.20.0
https://github.com/gvcgo/version-manager
https://github.com/version-fox/vfox
The Anti-996 License