Always run node with the --harmony flag

I always want to run Node.JS with the --harmony flag. Is there a way to easily have this flag turned on by default?

(Note: I'm running on Windows, so I only have access to Cygwin or Mingw as shells.)


If you are talking about running interactively, you can use a bash alias. Put this in your ~/.bashrc:

alias node="node --harmony"

(For the below: note that when I say "executable", I don't just mean binaries or ".exe files". "Executables" include anything that can be executed without explicitly invoking an interpreter, which includes scripts with a shebang.)

If you want to run an executable, e.g. within another script, you can create a shell script that launches the target with the extra flag:

Create a nodeHarmony and put it in your search path, e.g. /usr/local/bin:

#!/bin/sh

node --harmony "$@"

Then chmod a+x it.

Then execute nodeHarmony whenever you want that flag appended. If you want to replace the node executable, you could probably rename node to something else (e.g. node_original), name the script node, and use node_original within the script.

You could also create the equivalent Windows batch script, which would work outside Cygwin/MinGW:

@echo off

node --harmony %*

This would behave similarly, but may exhibit odd effects with some argument combinations, because the list would get parsed twice - once when executing the batch script, and once within the script when executing node. Some workarounds here.


If you are ready to recompile node.js, the article How to obtain harmony in your node.js says :

Once you’ve got the source code, open up deps/v8/src/flag-definitions.h and look for Line 115. Change the flag from false to true :

DEFINE_bool(harmony, true, "enable all harmony features")

Then compile Node :

./configure && make && make install

Apparently https://www.npmjs.org/package/setflags can be used to set the flags at runtime, however I couldn't get it to install.