gulp-nodemon icon indicating copy to clipboard operation
gulp-nodemon copied to clipboard

Running more than one instance?

Open ryexley opened this issue 11 years ago • 30 comments

Is it possible to configure this to run/monitor more than one app per build script??

I have an app in which I have an API and a sample client app, and I would like to be able to launch, monitor and restart both of these apps on change with my gulp script. As it is now, when I add two instances as below, seems like only the second one ever gets logged to the terminal console as having been started. Am I missing something, or does this not currently work?

gulp.task("default", function () {
    gulp.run("jshint", "sample-stylus");

    gulp.watch(["app/**/*.js", "specs/**/*.js", "sample/**/*.js"], function () {
        gulp.run("jshint");
    });

    gulp.watch("stylus/sample.styl", function () {
        gulp.run("sample-stylus");
    });

    nodemon({
        script: "app/index.js",
        options: "-e jade, js"
    });

    nodemon({
        script: "sample/index.js",
        options: "-e jade, js"
    });
});

ryexley avatar Jan 16 '14 14:01 ryexley

Don't think you're missing something, I experience the same issue.

robertklep avatar Jan 21 '14 11:01 robertklep

@ryexley do they both start, and only second one's log forwards to node? Or does only the second one start?

ColemanGariety avatar Jan 22 '14 06:01 ColemanGariety

@JacksonGariety it only starts the last one for me.

It seems to be a nodemon issue, as I experience the same problem when using the nodemon() function in a standalone script (here is a Gist to show the problem).

robertklep avatar Jan 22 '14 07:01 robertklep

@JacksonGariety it only starts the last one for me as well.

ryexley avatar Jan 22 '14 16:01 ryexley

@ryexley @robertklep I'll take a look this weekend.

ColemanGariety avatar Jan 23 '14 19:01 ColemanGariety

I mentioned remy in a comment regarding this issue in nodemon itself, so hopefully it'll get resolved soon.

ColemanGariety avatar Jan 29 '14 02:01 ColemanGariety

Ah, crap - this isn't actually linked to the issue that @JacksonGariety raised against nodemon. It's because, currently when you require in nodemon, it's a static instance due to the way the config works. I've got a feeling it's quite a bit of work to change it to support multiple instantiations of the module - though I'd be very open to discussing how to upgrade the code and open to PR.

The issue isn't starting multiple apps for nodemon to monitor, it's the config that nodemon uses to monitor that's the issue...

I've created a ticket https://github.com/remy/nodemon/issues/286 - my gut says that new instances of nodemon is the right/cleanest path, but there's no quick fix that I can think of (unless gulp-nodemon abstracts and creates a sandboxed instance of nodemon...again: messy, but it would (probably) work).

remy avatar Jan 29 '14 10:01 remy

@remy thanks, Remy, if you make a branch on nodemon for this issue I'll pull it and try to help out.

ColemanGariety avatar Jan 29 '14 18:01 ColemanGariety

I've also noticed that I have to run node app.js in another tab even if gulp nodemon is running in one already.

kevinSuttle avatar Feb 08 '14 05:02 kevinSuttle

@remy could this be fixed by running nodemon as a child process?

ColemanGariety avatar Mar 09 '14 19:03 ColemanGariety

Ah, bummer, was looking into this too and just found this issue. An alternative for starting multiple targets is executing multiple nodemon instances via cli using something like gulp-shell, at least until nodemon adds support for multiple instances.

ruimarinho avatar Apr 24 '14 00:04 ruimarinho

@remy any updated on this in nodemon 1.3.0? I'm getting ready to publish a new version of gulp-nodemon to npm.

ColemanGariety avatar Jan 07 '15 20:01 ColemanGariety

@JacksonGariety I'm still working on it, it's collected a lot of bug fixes and a few features, but the issue I'm now trying to resolve is getting all the tests to pass :-\ funsies.

remy avatar Jan 08 '15 21:01 remy

@remy need any help? I don't start school for three weeks so I've got a bit of free time on my hands.

ColemanGariety avatar Jan 08 '15 21:01 ColemanGariety

Any update on this issue?

redism avatar Mar 11 '15 02:03 redism

I've got this too - for now I'm having to combine services in one task when doing dev work (not great):

/Users/marksyzm/Documents/server/oxsrc/teoti/node_modules/nodemon/lib/nodemon.js:138
    utils.log.detail('ignoring: ' + config.options.monitor.map(function (rule)
                                                          ^
TypeError: Cannot read property 'map' of undefined
    at /Users/marksyzm/Documents/server/oxsrc/teoti/node_modules/nodemon/lib/nodemon.js:138:59
    at /Users/marksyzm/Documents/server/oxsrc/teoti/node_modules/nodemon/lib/config/index.js:79:7
    at ready (/Users/marksyzm/Documents/server/oxsrc/teoti/node_modules/nodemon/lib/config/checkWatchSupport.js:28:7)
    at /Users/marksyzm/Documents/server/oxsrc/teoti/node_modules/nodemon/lib/config/checkWatchSupport.js:61:9
    at ChildProcess.exithandler (child_process.js:742:7)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Socket.<anonymous> (child_process.js:1183:11)
    at Socket.emit (events.js:107:17)
    at Pipe.close (net.js:485:12)

marksyzm avatar May 26 '15 10:05 marksyzm

Experiencing the same issue when using gulp-nodemon. I have two tasks which each nodemons a separate node instance. Running either task by itself works perfectly fine, but trying to run both at the same time yields:

node_modules/nodemon/lib/nodemon.js:138
    utils.log.detail('ignoring: ' + config.options.monitor.map(function (rule)
                                                          ^
TypeError: Cannot read property 'map' of undefined

csvan avatar Jun 01 '15 08:06 csvan

so.. no fix for a year :(

BlueHotDog avatar Jul 29 '15 20:07 BlueHotDog

@BlueHotDog so.. no pr for a year :(

remy avatar Jul 30 '15 11:07 remy

What I do I run two console windows. I lay both applications to diff. ports with node.process.env . For all other duplicate issues I copy the whole app to a second .tmp folder and run gulp.replace . At the moment I restart the second gulp task by hand but I plan to create an empty file as soon as the first process finishes and to watch this file with the second process.

360disrupt avatar Sep 30 '15 15:09 360disrupt

@JacksonGariety @remy any progress on this? have 4 tasks each for a different app. running just runs the last one 4 times...

andyday avatar Feb 19 '16 19:02 andyday

I need that!

linxixuan avatar Apr 12 '16 08:04 linxixuan

I've not seen any pull requests for this feature yet, so I'm afraid I've not seen any progress on this yet. Will keep an eye out.

remy avatar Apr 12 '16 08:04 remy

Saw this on stackoverflow: http://stackoverflow.com/questions/34102947/gulp-run-multiple-node-scripts-in-parallel

Maybe this does the job?

bastianwegge avatar Jun 30 '16 09:06 bastianwegge

@remy Anything we can do to help this get along? Anyone running microservices would be very happy I'm sure!

brycejacobs avatar Aug 26 '16 15:08 brycejacobs

Happy to accept a PR. Not sure what the root cause of the problem is, so can't really direct.

On Fri, 26 Aug 2016, 16:42 Bryce Jacobs, [email protected] wrote:

@remy https://github.com/remy Anything we can do to help this get along? Anyone running microservices would be very happy I'm sure!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JacksonGariety/gulp-nodemon/issues/6#issuecomment-242771382, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA1hGx9bYBjeQhsTtmydqnaHbM-DQWOks5qjwlPgaJpZM4BaQ6v .

remy avatar Aug 26 '16 15:08 remy

Is this really still a thing?

mattkenefick avatar Feb 03 '17 16:02 mattkenefick

@mattkenefick We ended up landing on using a library named "concurrently"

package.json example:

"scripts":{ "server:one": "$(npm bin)/nodemon --watch services/one services/one", "server:two" "$(npm bin)/nodemon --watch services/two services/two", "start:dev": "$(npm bin)/concurrently "npm run server:one" "npm run server:two"" }

brycejacobs avatar Feb 03 '17 17:02 brycejacobs

I found a workaround using "just" Gulp:

Created a Task and an internal Task for each nodemon usage: GIST: https://gist.github.com/kirla3092/71b6f2e982343135fcc0ab3d360d5ac5

Maybe this helps someone. Know problem: "rs"-Command is not working. But this should be possible to solve.

kirla3092 avatar Jun 27 '17 14:06 kirla3092

I had the same problem (attempting to start two instances of nodemon from gulp) and found a fairly simple solution with the gulp-multi-process plugin.

Create a separate task for each instance of nodemon you wish to start...

gulp.task('start:server:1', () => {
  nodemon({ script: 'path/to/server1' });
});

gulp.task('start:server:2', () => {
  nodemon({ script: 'path/to/server2' });
});

...then create a single task to launch them using gulp-multi-process...

gulp.task('start:server', () => {
  gulpMultiProcess(['start:server:1', 'start:server:2']);
});

You can even include one instance of nodemon in the top level task, which in my case is the approach I've taken. I launch my main app in the top level task, then call gulpMultiProcess to launch my background worker processes.

mjy78 avatar Sep 20 '17 08:09 mjy78