Vadorequest Vadorequest - 15 days ago 5
Node.js Question

How to force npm to install specific version of package by default?

Is there a way to config npm not to install package using a lazy version like:

"coffee-script": "^1.11.1",


But

"coffee-script": "1.11.1",


And have this behavior become the default one? We usually don't want to use lazy versions, I prefer to manually upgrade everything to the latest from time to time rather than having a bug thrown up at my face after a new deployment due to a bug in one of my dependencies.

The only way to "do that" right now is to manually remove the
^
character every time after every
npm install
, which is a bit boring.

Answer

This is the command that will set a user variable in your npm configuration to always default to use the exact version when performing an npm installation of all packages.

Enter this command in your terminal:

npm config set save-exact=true

The new preference is stored in a user-based custom npm configuration file. It is located here:

~/.npmrc

Finally, you can verify the setting was saved with the command:

npm config ls

Official NPM docs here:

https://docs.npmjs.com/misc/config

https://docs.npmjs.com/files/npmrc

Comments