Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Last active June 20, 2018 13:59
Show Gist options
  • Save dreamyguy/becf5fb54540a77f2e63c7678e6ab8bd to your computer and use it in GitHub Desktop.
Save dreamyguy/becf5fb54540a77f2e63c7678e6ab8bd to your computer and use it in GitHub Desktop.
Reinforce Node version

Reinforcing node version

To specify which version of Node the app should be using, use the engines property on package.json, like so (in this case sticking to version 5):

{
  "name": "my-app",
  ...
  "engines": {
    "node": ">=5.0.0 <6.0.0"
  }
}

This one has the same effect:

{
  "name": "my-app",
  ...
  "engines": {
    "node": "^5.0.0"
  }
}

Docs:

engines is meant to set node version for dependencies. If you want to reinforce the use of the node version and throw an error, you can use a package like:

https://www.npmjs.com/package/engine-check

npm install --save engine-check or yarn add engine-check

Managing different versions of node locally

When dealing with node, the need to change node versions locally has become common place.

Save yourself a lot of headache and manage node through nvm (node version manager) only, if you can help it.

All other alternatives (installing node directly with curl, indirectly through binary installers or homebrew) are simply not as flexible.

Docs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment