Saturday, January 18, 2014

(Node.js) Use --harmony with supervisor

Currently I'm working on a web project and I'm using Node.js for it.

When testing it on my local computer,  I use supervisor (npm install -g supervisor) instead of using node directly. That is, to start my script, I use:
supervisor app.js
instead of:
node app.js
However, since I'm using the harmony mode (for keyword such as 'let'), supervisor seems can't start node with the '--harmony' flags, I must modify the script myself.

  • Using 'find . | grep supervisor' to find the location of the script: /usr/local/share/npm/lib/node_modules/supervisor
  • Edit ./lib/supervisor.js.
  • In 'function run (args)' :
Add:
function run (args) {
  var arg, next, watch, ignore, program, extensions, executor, poll_interval, debugFlag, debugBrkFlag, debugBrkFlagArg, harmony;
  while (arg = args.shift()) {
    if (arg === "--help" || arg === "-h" || arg === "-?") {
      return help();
    } else if (arg === "--quiet" || arg === "-q") {
      debug = false;
      util.debug = function(){};
      util.puts = function(){};
    } else if (arg == '--harmony') {
      harmony = true;

    } else if (arg === "--verbose" || arg === "-V") {
      verbose = true;
And:
  if (debugBrkFlag) {
    program.unshift(debugBrkFlagArg);
  }
  if (harmony) {
    program.unshift('--harmony');
  }
Save, and that's all.


Now I can use:







supervisor --harmony app.js

to start my project :)


3 comments: