NPM node validate expected version
Use package.json and add the lines
{
...
"scripts": {
"start": "node index.js",
"test": "lab tests/api.tests.js",
"preinstall": "node checkNodeVersion"
},
"engines": {
"node": ">=20",
"npm": "^10"
},
...
}
First set the engines
property to the version you wish to support, this is for Node 20 and up along with npm 10 or higher
Second add the preinstall
check command of node checkNodeVersion
to validate proper version
Third create a .npmrc
file in the root folder of your nodejs application and put this in the file
engine-strict = true