There is an old saying I find myself repeating often, "if it ain't broke, don't fix it". This may seem like common sense but with every software update that comes along, while there are often clear benefits to the upgrade, you may find your previously working code or project is no longer willing to play nice.
With Node, I'm always trying to stay current and in some cases I need to switch between Node versions when switching between projects. Here is the basics for switching Node versions using Homebrew on Mac OS.
First, find out what version of Node you currently have installed:
Next, lets check what version(s) of Node are already available on our system using the following command:
brew search node
You may need to install any missing version required if it's not already available locally. To do this, we can use the following command to get the latest stable release of each major version (just swap out the version number to the version you want to install):
brew install node@8
Once the correct version is installed we just need to unlink the old version:
brew unlink node@10
...and link the version we want to use:
brew link node@8
To ensure everything worked out as planned, check the node version to confirm:
Note: For best results, you should remove the node_modules folder in your project and rerun
npm install to allow Node to rebuild all the dependencies using the correct Node version.