• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Document current usage of .node-version file

.node-version File Usage

Q: Is .node-version read by multiple Node.js version managers?
A: Yes.

Q: Does .node-version have a defined common or standard file format?
A: No.

Q: So what compatibility is there across individual products?
A: Good question! Read on...

Supporting Products

Version managers for Node.js which read a .node-version file include (in alphabetical order):

  • asdf-nodejs Node.js plugin for asdf version manager. (macOS, Linux)
  • avn Automatic Version Switching for Node. (macOS, Linux)
  • chnode Changes shell's current Node.js version by updating $PATH (macOS, Linux)
  • direnv unclutter your .profile. (macOS, Linux)
  • fnm πŸš€ Fast and simple Node.js version manager, built in Rust. (macOS, Linux, Windows)
  • n Interactively Manage Your Node.js Versions. (macOS, Linux)
  • nenv Groom your app’s Node environment with nenv (macOS, Linux)
  • nodeenv Virtual environment for Node.js & integrator with virtualenv (macOS, Linux, Windows)
  • nodenv Manage multiple NodeJS versions. (macOS, Linux)
  • nodist Natural node.js and npm version manager for windows. (Windows)
  • nve Run any command on specific Node.js versions (macOS, Linux, Windows)
  • nvm-rust A cross-platform node version manager that doesn't suck (macOS, Linux, Windows)
  • nvm.fish Node.js version manager lovingly made for Fish. (macOS, Linux)
  • nvs Node Version Switcher - A cross-platform tool for switching between versions and forks of Node.js. (macOS, Linux, Windows)
  • rtx Polyglot switcher compatible with asdf plugins, built in Rust. (macOS, Linux)
  • setup-node (configuration) Set up your GitHub Actions workflow with a specific version of node.js
  • tea tea is the next-generation, cross-platform package manager from the creator of brew. (macOS, Linux)

Other products which read .node-version include:

  • Cloudflare Pages Build fast sites. In record time.
  • Hostman Hosting platform that deploys your web applications
  • netlify Instantly build and deploy your sites to our global network from Git.
  • paketo Your app, in your favorite language, ready to run in the cloud
  • preferred-node-version Get the preferred Node.js version of a project or user
  • render A Cloud for the New Decade
  • starship β˜„πŸŒŒοΈ The minimal, blazing-fast, and infinitely customizable prompt for any shell!

(Note: nvm does not support reading a .node-version file. See #4 for more.)

Suggested Compatible Format

If you are creating the file, a format with full compatibility across current tests is:

  • single line with unix line ending
  • three part numeric version e.g. 14.5.0

A leading 'v' is widely supported, so this will work with most implementations:

$ node --version
v10.15.3
$ node --version > .node-version

If you are reading the file in a new implementation, I suggest you also support optional leading v and any line ending. Allowing a leading v is common and gives nice symmetry with node --version. Allowing any line ending makes it easier for users and especially Windows users to create a file compatible with your product.

Compatibility Testing

Utility simple leading v partial Unix EOL No EOL Win EOL Notes
10.1.2 v10.1.2 10.2
asdf βœ… βœ… ❌ βœ… βœ… ❌
avn βœ… βœ… βœ… βœ… βœ… βœ… πŸ‘» #11
chnode βœ… βœ… βœ… βœ… βœ… βœ…
direnv βœ… ❌ βœ… βœ… βœ… ❌
fnm βœ… βœ… βœ… βœ… βœ… βœ…
n βœ… βœ… βœ… βœ… βœ… βœ…
nodeenv βœ… ❌ ❌ βœ… βœ… βœ…
nenv βœ… 🧩 #8 🧩 #8 βœ… βœ… βœ…
nodenv βœ… βœ… 🧩 #1 βœ… βœ… βœ…
nodist βœ… βœ… βœ… βœ… βœ… βœ…
nve βœ… βœ… βœ… βœ… βœ… βœ…
nvm-rust βœ… βœ… βœ… βœ… βœ… βœ…
nvm.fish βœ… βœ… βœ… βœ… βœ… ❌
nvs βœ… βœ… βœ… βœ… βœ… βœ…
rtx βœ… βœ… βœ… βœ… βœ… βœ…
setup-node βœ… βœ… βœ… βœ… βœ… βœ…
tea βœ… βœ… βœ… βœ… βœ… βœ…

The columns show whether the utility supports a file containing:

  • simple: three part numeric version, like 10.1.2
  • leading v: numeric version with a leading v, like v10.1.2
  • partial: numeric version with less than three parts, like 10.2
  • EOL: end of line characters used in file, Unix \n or Windows \r\n or none

References

For interest, here is a discussion about similar .ruby-version file format. The commonly supported format is a simple version, with some products adding fuzzy matching. (Ruby is likely the inspiration for some of the .node-version usage, especially nodenv which uses rbenv syntax.)

A discussion about a possible standard format for .node-version was started in 2016 initially covering desirable (new) features and then more focus on existing usage, but did not reach consensus.

StackOverflow: What uses / respects the .node-version file?