Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing CLI arguments through gulp-nodemon

I am using the npm package gulp-nodemon to start my webserver.

The problem I am having is that I cannot pass CLI arguments to my server script.

I would like to write something like this:

gulp --argument1 value1

And the nodemon then should call coffee server.coffee --argument1 value1

My current nodemon task:

# nodemon development server
gulp.task 'nodemonServer',  () ->
  nodemon({
    script: 'server.coffee'
    ext: 'coffee'
    watch: ['server/', 'server.coffee']
    env: { 'NODE_ENV': 'development' }
  })
  .on 'crash', () ->
    notifyServerError()

I tried writing script: 'server.coffee --argument1 value1' but I am getting a strange error: File not found: C:\Users\user\projectRoot\"server.coffee

Yes, with the " in the file path. Here is the log:

[13:13:10] [nodemon] starting `coffee.cmd "server.coffee --argument1 value1"`
File not found: C:\Users\user\projectRoot\"server.coffee

Thanks.

like image 414
Nick D Avatar asked Mar 11 '26 20:03

Nick D


1 Answers

Use args to pass any arguments for coffee command. This are the agruments passed AFTER the script filename.

Use exec to pass any coffee options along with the coffee executable. These are passed BEFORE script filename.

var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
gulp.task('nodemonServer', function () {
  nodemon({
    script: 'server.coffee',
    exec: 'coffee -p',
    args: ['--argument','value1'],
    ext: 'coffee'
  , env: { 'NODE_ENV': 'development' }
  })
})

To see the actual command used by nodemon, use DEBUG=nodemon

DEBUG=nodemon gulp nodemonServer

which logs:

  nodemon bus new listener: reset (0) +0ms
  nodemon bus new listener: reset (0) +6ms
  ...
[13:47:20] [nodemon] starting `coffee -p server.coffee --arguments value1`
  nodemon spawning +0ms coffee -p server.coffee --arguments value1
like image 50
hassansin Avatar answered Mar 14 '26 08:03

hassansin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!