NodeJS switcher based on package.json.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
test
.bumpedrc
.editorconfig
.gitattributes
.gitignore
.npmignore
.npmrc
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
package.json

README.md

nodengine


nodengine
Automatic NodeJS version switcher

Last version Build Status Dependency status Dev Dependencies Status NPM Status Donate


nodengine is an automatic NodeJS switcher based on node version declared in package.json.

It needs a global version manager as n or nvm.

If you want know when a new version of node is released, follow our @nodengine bot.

Install

$ npm install nodengine --global --production

Usage

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.

Automatic switching

Enabling automatic switching consist in a little shell script for check if package.json exists and then runs nodengine.

Add the follow snippet in a file loaded by your shell agent, for example, .extra.

function chpwd() {
  local PKG
  PKG=$PWD/package.json
  if [ -f "$PKG" ] && [ "$NODENGINE_LAST_DIR" != "$PWD" ]; then
    nodengine
    printf "\033[36m%s\033[0m \033[90m%s\033[0m\n" "nodengine" "$(node --version)"
    NODENGINE_LAST_DIR=$PWD
  fi
}

function cd() { builtin cd "$@" && chpwd; }
function pushd() { builtin pushd "$@" && chpwd; }
function popd() { builtin popd "$@" && chpwd; }

Fetching new versions

The program use a local cache for avoid fetching versions of node all the time.

By default, new versions of node will be fetched after 5 days.

You can setup the interval using NODENGINE_INTERVAL

For example, if you want to fetch all versions every time that you run the program:

NODENGINE_INTERVAL=0 nodengine

License

MIT © Kiko Beats