Allow me to introduce you to NVM, or short for Node Version Manager. This tool allows us to have a more intuitive process when it comes to installing, maintaining and switching between the different versions of Node.js that are either stable releases or not. While it's still common practice to utilize tools such as Homebrew to install Node.js in your machine, I hope, with this article, to convince you not to.
In the introductory lines of this article, I mentioned using tools such as NPM (which comes bundled with Node.js) being common practice among professionals nowadays. What is not so often talked about, is how prone to errors you become when you use a package manager such as Homebrew to install Node.js and consequently another package manager which is, in this case, NPM.
Why not Homebrew
Personally, I have run into a multitude of bugs and errors when working with ReactJS and trying to install a given version of Node.js along with my project’s dependencies. Another reason why I decided to stop using Homebrew for my Node.js needs, is that while learning some React Native, the instructor I had been working with was using a different version of Node.js that I was. Naturally, I tried installing said version via Homebrew which led me to some good 30 minutes of tinkering around in an attempt to fix the versioning issues I was having. All in all, we shouldn’t be using a package manager to install another package manager.
Note: While this is a niche article for users with specific needs, I’d like to keep it as beginner-friendly as possible, and as such, I have included how to install Xcode’s developer tools and how to uninstall Node.js via Homebrew in case someone out there has already installed it and wishes to undo the process. Skip the first step if you already have either Xcode or developer tools installed on your machine.
Installing Node.js Using NVM
With Node.js and NVM installed, you can now reliably use NPM and switch between its versions in a more efficient way. Whether you're working on that new ReactJS app or else, the NPM community has certainly got you covered with Node packages that can help you in your journey. Happy coding!