It's crazy that 12.13.0 is now the latest long term support version of nodejs! At work today we discovered that when we all boot up a new terminal shell and run "node -v" to get the current node version, we would all get a different number! One person was on 12.13, one was on 11.15, one was on 10.something, and one guy was even using v6.4! We had to do something about this madness
I like to keep things simple, and what I like to do is for every project just create a ".nvmrc" file and ".node-version" file in the project root (same level as package.json). Both files only have a single line (they can have more but this is all that's needed), and this is the contents of each of these files for my current project.
You may not need both files, but I like to include both the .npmrc and .node-version because that's for me what seems to cause the least hassle in the most situations. My node version manager of choice is nvm (yes, there other options- nave!) For users who have nvm installed, the system will use the version installed by nvm. For users who for some reason are not using nvm, the project will look at .node-version and thus should still try to use the correct node version.
If for some reason you did not want to use the solution above then you can enforce a node version right from package.json. The catch is that you still need to create a .npmrc file that has this contents:
Then you can add this to package.json:
For more info on this, see this stack overflow post.
The great thing about setting up your projects' node versions in this way is that it is idiot-proof. It's at easy as it can possibly be- you don't need to do anything or think about it at all! haha. I'm a fan of automating as much as possible, and this is just one more tip to streamline any Node.js developer workflow. I can't see why you would NOT want to set this up for all node projects...
If you have any comments or suggestions please do leave a comment below!
The posts on this site are written and maintained by Jim Lynch. About Jim...