TIL how to quickly create a .nvmrc file
POSTED ON:
TAGS: node buildtools
In my job, we switch node versions a lot, using something like Node Version Manager
to handle all the heavy lifting.
Which means, lots of weird hacks to figure out which node version is running in a specific project.
Weird hacks we've done:
-
We tried to put the node version in the readme file. (Nobody ever reads it)
-
We tried to lock down the node version in
package.json
(sometimes it works, sometimes it doesn't?) -
We start every project by going
nvm i
, which looks for a.nvmrc
file. (BOOM! This works for unix devices! Windows... nah. See this convo)
To explain, your .nvmrc
file saves your node version into the project. Node Version Manager finds that file, installs that version if it doesn't exist, and switches to that version. It's fantastic.
And to automatically generate that file: node -v > .nvmrc
That >
is a bash command to send data from the left, to the riht.
Related TILs
Tagged: node