NodeJS switcher based on node version declared in
package.json
.
It needs a global version manager as n or nvm.
$ npm install nodengine --global --production
Set the desired version range in the package.json
"engines": {
"node": ">= 0.10"
}
Then just run nodengine
to change the current node version to version declared into package.json
.
It will use the highest version that satisfies the range.
Manual switching can be avoided. Add the following below to your environment depending on your shell choice.
echo "\nchpwd () {\n nodengine\n}" >> ~/.zshrc
# Enable nodengine autoswitching
cd () { builtin cd "$@" && chpwd; }
pushd () { builtin pushd "$@" && chpwd; }
popd () { builtin popd "$@" && chpwd; }
chpwd () {
FILE=$PWD/package.json
if [ -f $FILE ];
then
nodengine
fi
}
MIT © Kiko Beats