How to Specify Exact Node Version for a NPM Project?

In order to ensure specific version of node used in the npm project you can add entry to package.json and create .npmrc file.

If you want to make sure every developer and environment uses the same node and npm you just need to add engines entry to package.json.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"name": "my-project",
"version": "1.0.0",
"description": "My Application",
"engines": {
"node": ">=10.0.0 <11.0.0",
"npm": ">=6.0.0 <7.0.0 "
}
}

```

But this is not enough. Now you must force enviroment to be strict to those values.

In the past you could pass `"engineStrict": true` property to `package.json` to do so. But it is deprecated now, and it gives only warning.

Instead, if you still want to be sure that specified versions are used you just need to create `.npmrc` in the sam catalouge with `engine-strict=true` value:

```bash
engine-strict=true

.npmrc is used to define npm settings. As said in the official docs:

npm gets its config settings from the command line, environment variables, and npmrc files.

With the above settings the npm makes sure, the strict versions of engines are used in the project. Now if someones try to run npm install with non-matching node or npm versions it will be stopped with error response.

With such configuration you make sure, there are no unexpected changes in the package.json or package-json.lock files. That’s it!