Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What uses / respects the .node-version file?

Tags:

node.js

nvm

I've searched Stack Overflow and GitHub (for both node and nvm) for an answer, but to no avail.

In some repos (like GitHub's Atom text editor, for instance), I've come across a .node-version file. It seems to be analogous to the .ruby-version standard file that works with any Ruby version manager to set the current version of Ruby correctly for the project.

But as far as I can tell from its documentation, nvm (Node Version Manager) only respects a .nvmrc file - it mentions nothing about a more general .node-version file. And there's no mention of .node-version in node's documentation (and I wouldn't expect there to be, since it doesn't ship with a version manager out of the box). I'm not aware of any other node version manager in heavy use.

So my question is, what is .node-version? What tools actually use it? Is it just an alias for .nvmrc, or am I missing something here?

like image 301
wisew Avatar asked Dec 11 '14 15:12

wisew


People also ask

What does node version file do?

node-version file. It seems to be analogous to the . ruby-version standard file that works with any Ruby version manager to set the current version of Ruby correctly for the project.

Which can be used to check the version of node?

Check your Node version in one step. Using npm to check your node version (and also update it) Managing your Node versions with nvm.

What is .nvmrc file?

nvmrc file containing a node version number in your project. You can use the nvm —-help to check other options. After that you can simply run commands like nvm use, nvm install and nvm run etc. This will the default node. js version defined in .

What version of node is used in production?

The Node JS website states that “Production applications should only use Active LTS or Maintenance LTS releases” (Node JS org, 2020). This all means that if today you start learning with Node JS 16, you are good to deploy a production app with this version till March 2024.


2 Answers

(disclosure: I maintain http://nvm.sh)

The most-used version managers for node are without a doubt nvm, nave, and n.

nvm is for modifying individual shell sessions to use the version you want. nave is for launching subshells with the version you want loaded. n is for switching a single system-wide version of node.

nvm uses a .nvmrc file, which like .ruby-version, contains the version-ish string X you'd normally couple with nvm use X or nvm install X. nvm use or nvm install by itself will locate the .nvmrc file, as will simply sourcing nvm upon opening a new shell.

It appears nave supports a .naverc file, but I'm not too familiar with its usage.

n doesn't appear to support any such config, but as it's system-wide, it doesn't really make as much sense to do so.


avn supports .node-version and attempts to provide automatic version switching by hooking into cd, after nvm decided that was too invasive a behavior to include.

like image 168
LJHarb Avatar answered Oct 06 '22 16:10

LJHarb


There are a few version managers for node.js respecting .node-version file:

  • avn - Automatic Node Version Switching
  • nodenv - Yet another version managers
  • asdf - Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more, provided you configure it accordingly
  • nvs - Node Version Switcher

There may be some other version managers, but I'm not aware of them.

I don't know which particular version manager Atom uses. nodenv have more stars on GitHub, but avn looks more mature and better maintained for me, not to mention its compatibility with both n and nvm.

like image 38
Leonid Beschastny Avatar answered Oct 06 '22 16:10

Leonid Beschastny