Let ZSH automatically update your node version
because typing `nvm use 19.3.0` is so 2011
I switch between projects all day.
The projects I am switching between use different node
versions.
Here is an example of what it looks like when I switch projects.
cjb/really_good_code/older_project
$ cd ../shiny_new_project
cjb/really_good_code/shiny_new_project
$ bin/dev
[ERROR] [plugin copy-for-admin] inputPath.replaceAll is not a function
53 β ... dehash = inputPath => inputPath.replaceAll(replaceHashRegex, '');
π₯π₯π₯π₯π₯π₯π₯ EVERYTHINGS BREAKING π₯π₯π₯π₯π₯π₯π₯
This error came from the "onEnd" This error came from the "onEnd" callback registered here:
error Command failed with exit code 1.
...
π₯π₯π₯π₯π₯π₯π₯ DEPRECIATED / NEVER WORKED π₯π₯π₯π₯π₯π₯π₯
Exception raised: RuntimeError
Command failed with status (1): [yarn run esbuild-dev...]
π₯π₯π₯π₯π₯π₯π₯ ITS ALL WRONG ?? p > np π₯π₯π₯π₯π₯π₯π₯
...
cjb/really_good_code/shiny_new_project
$ nvm use '19.3.0'
cjb/really_good_code/shiny_new_project
$ bin/dev
[Server] * Puma version: 5.6.5 (ruby 3.0.2-p107) ("Birdie's Version")
[Server] * PID: 18036
[Server] * Listening on http://0.0.0.0:4000
[Server] * π You are awesome. This project works great.
[Server] Use Ctrl-C to stop
Additionally I LOVE to forget CLI commands, and version numbers.
No one forgets a CLI command, quite as quickly as I do.
(Weird flex, but ok?)
SO I let my zshell manage my node version manager.
Simply plop this little bash script at the bottom of your ~/.zshrc
# .zshrc
# Change node version based on .nvmrc
function change_node_version {
nvmrc="./.nvmrc"
if [ -f "$nvmrc" ]; then
version="$(cat "$nvmrc")"
nvm use $version
fi
}
add-zsh-hook chpwd change_node_version
change_node_version
Now simply ensure there is an .nvmrc
file at the root of all of your projects.
It should look something like this.
19.3.0
And there ya go. Switching projects looks more like this
cjb/really_good_code/older_project
$ cd ../shiny_new_project
Now using node v19.3.0 (npm v9.2.0)
cjb/really_good_code/shiny_new_project
$ bin/dev
[Server] * Puma version: 5.6.5 (ruby 3.0.2-p107) ("Birdie's Version")
[Server] * PID: 18036
[Server] * Listening on http://0.0.0.0:4000
[Server] * π You are awesome. This project works great.
[Server] Use Ctrl-C to stop
Now I spend way more time doing what I do best.
$ heroku run --? --verbose --help
If youβre looking for a team to help you discover the right thing to build and help you build it, get in touch.
Published on November 30, 2023