How to check if Node.js supports ES6 language feature

NAVIGATION

Node uses Chrome V8 JavaScript engine

Way #1, Easy - Compatibility Table

Way #2, Hard - Backtrack V8 version

Two ways to check

“Does Node have built-in Promises?”

Do you have to use a library for Promises or are they supported out of the box? What about string templates or destructuring assignment? What about the version of Node you’re running in production?

Node uses Chrome V8 JavaScript engine

New language features trickle down to Node.js in phases. Node uses Google’s V8 JavaScript engine for language implementation. New language features in Node depend on them being implemented first in V8. The V8 project pushes forward steadily and the team releases a new version roughly every six weeks. Then it’s up to the Node team to take up the new changes and incorporate them in Node.js.

Because the speed of change is this fast, it can be hard to try manually to list the features. Hand curated lists lose freshness as soon as a new version of Node is rolled out. Instead of trying to manually list the features, here are two strategies that allow you to determine whether a language feature is implemented in Node.

Way #1, Easy - Compatibility Table

Dynamically generated compatibility tables are useful and stay better up-to-date. Information can be kept fresh by basing evaluation criteria in small tests that check the presence of a language feature. A popular dynamically generated list is the one at kangax.github.io. It shows a list of features for all major JavaScript engines. Instead of looking at list of all features, we are interested only in what is available in Node.js. For Node specific list, node.green can be used, that leverages from the same data as kangax.

"When were ES6 string templates included in Node?"

node-green-template-literals.png

Checking compatibility table reveals us they were fully supported from Node.js v4.3.2.

Way #2, Hard - Backtrack V8 version

Specific features can be tracked down by looking at the V8 version included in Node. Since Node.js leverages Chrome V8 for JavaScript engine, figuring out what version of V8 is included in Node tells us which language features are supported. The V8 version included in Node can be printed out with node -p process.versions.v8.

What features are supported in a V8 version can be determined from Google’s V8 project resources. The V8 team keeps an issue tracker at bugs.chromium.com. The tracker has dedicated harmony label for upcoming language features. The V8 project also includes a conformance status document tested against Official ECMAScript Conformance Test Suite. The report is updated and versioned along with other V8’s source code. The report can be found in test/test262 directory for each branch of V8.

"Is destructuring assignment part of Node 5.8.0?"

$ node -p process.versions.v8
4.6.85.31

Node 5.8.0 embeds version 4.6.85.31 of the V8 engine. In the V8 issue tracker, the ticket for for destructuring assignment is #811 Implement destructuring. Then, in the 4.6.85 branch of V8 that used by Node, the ES conformance test tells us that much of #811 tests are skipped or failing.

# Destructuring
# https://code.google.com/p/v8/issues/detail?id=811
'language/statements/for-of/body-dstr-assign': [FAIL],
. . .
# https://code.google.com/p/v8/issues/detail?id=811
’language/expressions/assignment/destructuring/*': [SKIP],

This tells us that destructuring assignment is not part of Node 5.8.0.

Two ways to check

Language features become available in batches in Node.js and depend on them being implemented in V8 engine first. Manually curated feature lists become quickly outdated. For an evergreen way of checking feature availability you can use a dynamically generated feature list or backtrack the specific version of V8 engine used in Node.

See also: For an easily digestible list of features that make up the ES6 spec you can refer to es6-features.org. For Node's own documentation for ES6, check ECMAScript 2015 (ES6) in Node.js.

Node doesn't wait for your database call to finish?

Node doesn't wait for your database call to finish?

Learn how asynchronous calls work and make your app run as you intended. Get short email course on asynchronicity and two chapters from Finish Your Node App.

Loading Comments