Because JavaScript is an ever-growing programming language in terms of popularity and usability, so are the different ways of using its toolings such as Node.js. Let’s say you’re working on a new ReactJS app. You are most likely to end up using Node.js for the backend. More specifically, its core functionalities such as NPM. What if I told you there’s a reliable way of getting up and running with Node.js and, consequently, NPM?
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.
Installing NVM
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.
Uninstall any instances of Node.js via Homebrew. Type the following in the same order as they appear:
Check which version of NVM got installed. This should produce an output with the version number. Type:
Installing Node.js Using NVM
First, let's list all versions available for download. This should produce an output with all Node.js versions. Type:
To install the latest stable version, as of early 2020, type:
Finally, let's check which versions of both Node.js and NPM are currently being used. Type:
Conclusion
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!
Top comments (2)
Great article Carlos. I would suggest to write the command in the article instead of using picture so people can easily copy and paste those.
Really helped me. I agree with Dimitrij on writing out the commands instead of using pictures and having alternate text on the images please so others can be helped by this too! 😊