.node-version and .npmrc
|
v12.13.0 |
Why Two Files?
Could Alternatively Use "Engines" in Package.json
engine-strict=true
"engines": { "node": ">=10.0.0", "npm": ">=6.0.0" },
Make It Easy & Automatic
nvm use
Writings about one coder's stories & experiences.
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
.node-version and .npmrc
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.
Why Two Files?
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.
Could Alternatively Use "Engines" in Package.json
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:
engine-strict=true
Then you can add this to package.json:
"engines": { "node": ">=10.0.0", "npm": ">=6.0.0" },
For more info on this, see this stack overflow post.
Make It Easy & Automatic
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...
nvm use
If you have any comments or suggestions please do leave a comment below!
0 Comments
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorThe posts on this site are written and maintained by Jim Lynch. About Jim...
Categories
All
Archives
March 2023
|