What does `node --harmony` do?

Javascriptnode.js

Javascript Problem Overview


A node application has required me to run node with a harmony flag, like:

node --harmony app.js

What is this harmony flag? What does it do and why can't the app run without it?

I've tried looking into node command-line options (node --help), but it doesn't provide any details either. Node docs weren't of any help either.

Javascript Solutions


Solution 1 - Javascript

Typing man node has this on the harmony flag:

 --harmony_typeof (enable harmony semantics for typeof)
       type: bool  default: false
 --harmony_scoping (enable harmony block scoping)
       type: bool  default: false
 --harmony_modules (enable harmony modules (implies block scoping))       
        type: bool  default: false
 --harmony_proxies (enable harmony proxies)       
        type: bool  default: false
 --harmony_collections (enable harmony collections  (sets,  maps,  andweak maps))
       type: bool  default: false 
 --harmony (enable all harmony features (except typeof))
       type: bool  default: false

So --harmony is a shortcut to enable all the harmony features (e.g. --harmony_scoping, --harmony_proxies, etc.) From this blog post, it seems harmony enables new ECMAScript 6 features in the language. The reason your file won't run without harmony is because app.js is probably using non-backward compatible features from the new ECMAScript 6 standard (like block scoping, proxies, sets, maps, etc.)

Solution 2 - Javascript

If you want to run ECMAScript 6 features in older version of nodejs, you can use --harmony flag. Latest version of node supports ES6 so no need of --harmony flag

Solution 3 - Javascript

It enables harmony modules in node js: http://wiki.ecmascript.org/doku.php?id=harmony:modules

Solution 4 - Javascript

As mentioned in the Node Documentation, --harmony flag enables the non stable but tobe soon stabled features of ES6

> The current behaviour of the --harmony flag on Node.js is to enable staged features only. After all, it is now a synonym of --es_staging. As mentioned above, these are completed features that have not been considered stable yet. If you want to play safe, especially on production environments, consider removing this runtime flag until it ships by default on V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for further Node.js upgrades to break your code if V8 changes their semantics to more closely follow the standard.

Solution 5 - Javascript

All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged, and in progress features:

  • All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.

  • Staged features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag: --harmony.

  • In progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.

source: https://nodejs.org/en/docs/es6/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjsalonenView Question on Stackoverflow
Solution 1 - JavascripttheabrahamView Answer on Stackoverflow
Solution 2 - Javascriptuser7913653View Answer on Stackoverflow
Solution 3 - JavascriptEli AlgrantiView Answer on Stackoverflow
Solution 4 - JavascriptIgnatius AndrewView Answer on Stackoverflow
Solution 5 - JavascriptAravinView Answer on Stackoverflow