Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Explicitly & Automatically Set Your Project's Node Version

10/21/2019

0 Comments

 
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.

v12.13.0

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.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Want FREE access to
    my daily stock tips 
    ​newsletter called,
    "The Triple Gainers"?

    Sign up here!

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021