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?
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)
});
                        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");
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With