Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodemon : Passing arguments to the executable when using as a required module

I'm trying to start a script with nodemon, using it as a required module, and I cannot pass arguments correctly.

For example, for

var args = [ 
  process.argv[0], '--harmony', 
  '/path/to/script.js', '-i', 'logs'
];`

I'm expecting the script to be launched as :

node --harmony /path/to/script.js -i logs

But it doesn't work and all I can manage to get is

node --harmony /path/to/script.js -i logs /path/to/script.js

This is what I tried :

var app = require('nodemon')({
    script: args[2],
    exec: args.join(' ')
});

I know about execMap, but it's no good as I cannot pass arguments at the end anyway.

How can it be done?

like image 961
Yanick Rochon Avatar asked Mar 25 '14 20:03

Yanick Rochon


2 Answers

Skimming through the source code, I found the args config options (undocumented...). It turns out to be what I needed.

var app = require('nodemon')({
  exec: args.slice(0, 2),
  script: args[2],
  args: args.slice(3)
});
like image 141
Yanick Rochon Avatar answered Oct 13 '22 09:10

Yanick Rochon


I recommend use gulp with nodemon

var argv = require('optimist').argv
    gulp = require("gulp"),
    nodemon = require("gulp-nodemon");

gulp.task("default", [], function(){
   nodemon({
       script: 'app.js',
       ignore: ["public/*"],
       env: {'NODE_ENV': 'development'},
       args: ["--port="+argv.port],
       exec: "node --harmony"
   }).on("start");
});
like image 25
André Ferreira Avatar answered Oct 13 '22 08:10

André Ferreira