Should you commit .nvmrc to GIT in your NODE projects?

Viewed 2136

As a developer I want to have multiple projects that can use different versions of NODE js. Also when I checkout new project from a GIT repository I ideally want to run just one command and all things would be automated.

Given that file .nvmrc allow for automatic switching of NODE versions per directory. And given that my project is built on top of that specific version of NODE and might not work in any other.

Should I commit it to GIT?

This might be opinion based question, but I am really asking on disadvantages of doing so. Are there any risks?

--

Background:

This was like my first commit, after I started working in the new company. My ex-colleague declined that PR (without previous debate), and when I asked, he told me that its a developer responsibility to use proper version.

Well I added .nvmrc to .gitignore and used it anyways. Otherwise I would need to type nvm use xx every time I opened a new window in terminal.

1 Answers

There is nothing inherently bad about specifying the version of your tool with which the project is being run (or for that matter, any project specific files as nicely discussed here), because:

  • It's clear what you are targeting, allowing you to use those features in that specific version.
  • Convenient for project setup.
  • Can be ignored (in some cases) by people who don't want to use it.
  • Does not enforce anyone to use it (like for .nvmrc).

Plenty of people and many node projects commit their .nvmrc file.

I guess what your colleague meant is one of the following (just guessing):

  • You as a programmer maintain the project and its version, not the other way around.
  • The project "shouldn't know" about what version of node you are using.
  • "Locks-in" the development of the project to one version or not allowing it to change and evolve versions in the future.
Related