nodengine

3.5.0 • Public • Published


nodengine

Automagically switch your Node.js version

based on `package.json`

Last version

NPM Status

nodengine is an automatic way to switch your Node.js version per project reading engines fields at 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

Package Sidebar

Install

npm i nodengine

Weekly Downloads

1

Version

3.5.0

License

MIT

Unpacked Size

11.3 kB

Total Files

10

Last publish

Collaborators

  • kikobeats