ProTip™: `nvm install` Your `.nvmrc`
Published
When working on a project that uses Node, npm, or similar it’s common to use nvm to manage your Node.js version. Right, it’s in the name: Node Version Manager.
A quick way to improve the developer experience (DX) is to set the Node version in a .nvmrc
file in the root of the project. This means you can omit the version when typing nvm install
and nvm use
commands e.g.
-nvm install 20.15.0
-nvm use 20.15.0
+nvm install
+nvm use
Assuming there’s a .nvmrc
file with v20.15.0
as the file contents.
An even better tip is that you only need to run nvm install
to install (if required) and use the Node version specified in your .nvmrc
. I found this wasn’t really documented well at all1, but having a single-command one-liner as part of your README (you do have one of those, right?) steps for setting up the project is *chef’s kiss* 🤌.
Here’s my typical workflow for adding & documenting nvm
support in a project:
nvm install --lts # Unless necessary, I default to the latest LTS release
node -v > .nvmrc # No need to manually copy & paste
echo '- `nvm install`' >> README.md # Tell the world
Remember:
nvm install
It’s all you need. You can thank me later for all seconds saved. :)
It’s buried deep in the README: https://github.com/nvm-sh/nvm/blob/ff1257e8e3059ae01928c4261a41de2260bcd968/README.md#L566↩︎
I love hearing from readers so please feel free to reach out.
Reply via email • Subscribe via RSS or email
Last modified #protip #programming #documentation #dx