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

StackOverflow https://stackoverflow.com/questions/22645082

  •  21-06-2023
  •  | 
  •  

Question

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?

Était-ce utile?

La solution

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)
});

Autres conseils

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");
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top