Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify/enforce a specific node.js version to use in package.json?

Tags:

I am searching for a way to break the build, if a user is using a different node.js version as defined in the project.

Ideally to put some checks in grunt or bower or npm to stop, if a certain npm/node version is not used to run the current build.

like image 870
cilap Avatar asked Feb 09 '15 12:02

cilap


1 Answers

Even though engineStrict is deprecated, you can still accomplish this behavior without needing to use an additional script to enforce a Node version in your project.

  1. Add the engines property to your package.json file. For example:

    {   "name": "example",   "version": "1.0.0",   "engines": {    "node": ">=14.0.0"   } } 
  2. Create a .npmrc file in your project at the same level as your package.json.

  3. In the newly created .npmrc file, add engine-strict=true.

    engine-strict=true 

This will enforce the engines you've defined when the user runs npm install. I've created a simple example on GitHub for your reference.

like image 182
blimmer Avatar answered Sep 22 '22 11:09

blimmer