16

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.)

Randomblue
  • 3,585

5 Answers5

14

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.

Bob
  • 63,170
4

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
harrymc
  • 498,455
1

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

balupton
  • 585
0

Why don't you config the package.json with a scripts command?

For example, add to package.json:

  "scripts": {
    "start": "node --harmony server.js"
  }

Then run in cmd (in the project directory):

npm start

Noam Manos
  • 2,222
0

You can edit node.js file and:

  1. Search for a variable that checks its setting for "--harmony" or "harmony", something like:

    if (variable_name == 'harmony') ...
    
  2. Set this variable earlier in code:

    var this_variable_name = 'harmony';
    
pbies
  • 3,550