Upgrading to Node.js 4
Nowadays there are lots of projects using tools like npm, grunt, gulp, webpack, jspm, karma, mocha, jasmine… All of these tools run by using Node.js (Node). At the beginning of September, Node was upgraded to version 4 from version 0.12, including tons of useful features and fixing a big community fracture.
A short Node history lesson.
You might be asking now where are versions 1, 2 and 3. Node has a large community of people willing to develop stuff for it, but it was also owned by a company called Joyent. The problem was that Node wasn’t updating at the same pace as people wanted it to be, using an outdated version of the V8 engine and not adding new cool (and useful) language capabilities, like ES6 support.
So we have Node, an open source library with a large community who wants it to move faster and a company that is not capable of keeping-up with the pace. What can possibly happen? A fork happened. It was called io.js and included a new version of V8 and initial support for ES6.
Node always followed a versioning system where they had a 0.x version. Odd numbers were used for development versions and even numbers for production versions. The developers of io.js decided to follow semantic versioning. As they introduced breaking changes on the API they kept upgrading the major version, getting to 3.0.
At this point there was a big problem: the Node community was fractured between developers using Node and developers using io.js.
Luckily the world is still not crazy enough as to keep with the madness of maintaining basically two versions of the same thing, and the two projects decided to merge under a new umbrella: the Node.js Foundation. This new entity decided to use io.js as the base code for the official Node version, and when the merge was ready they released it as Node.js version 4, because io.js was already in version 3.
Ok, enough history. How do I upgrade?
At last we get to the interesting part.
To update Node on a Mac you usually run something like
brew upgrade (updates all of your
brew packages) or
brew upgrade node.
If you update accidentally (or not) Node in your machine, you may find that some of your projects are not working anymore. Don’t panic, everything will be ok. You just need to go to your project, remove the
node_modules folder and reinstall again all the dependencies in your
So, if you have something like this:
You will need to remove the
dependencies keys from the
package.json file and run this:
Why are we removing all the dependencies? The problem is that some packages depend on some others, and it is really difficult to get what is going on when some of the dependencies are not working properly. So this is a quick fix. The caveat is that if you have a lot of dependencies the command might be a little long, but it is something that your are only going to do once. Just do it now and start enjoying the blessings of Node 4.