My team recently upgraded our Node version from 0.10 to 4.0 for a big app we are working on. Lots of improvements came in the upgrade, but by far, my favorite is all of the ES6 features now available natively in Node.
I thought I would go over a few of my favorite features, focusing on what is available and why I like it, rather than the specifics of each feature. There are a huge number of resources like MDN which can explain the specifics better than I can!
let and const
If I’m being honest, var isn’t that bad. Functional scoping is admittedly weird, but I don’t know that I’ve ever encountered an actual bug from it. let just makes more sense though; it works like every other programming language.
This is my absolute favorite ES6 feature. Arrow functions solve the issue of anonymous functions failing to bind the
this variable correctly. As a bonus, they also have a much more succinct syntax. They play really well with classes and libraries like lodash.
Promises are fantastic, and now you no longer need a separate library for them. ES6 native promises follow the same Promises/A+ standard as all the most popular libraries, so they can interop seamlessly with them.
Things You Don’t Get
Node, at least in version 4.0, does not support all of ES6. Also, most of the features are only available in strict mode, but you’re already using that, right? Some of the great ES6 features you don’t get include:
- Default function parameters
- Array and object destructuring
For an exhaustive list of what is and isn’t supported, check out this table.
But honestly, the things you do get are a big win, as is not having to run your code through a compilation step to get it. If you aren’t using ES6 in your Node.js apps, now is the time to start!