gulp-nodemon
gulp-nodemon copied to clipboard
Running more than one instance?
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"
});
});
Don't think you're missing something, I experience the same issue.
@ryexley do they both start, and only second one's log forwards to node? Or does only the second one start?
@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).
@JacksonGariety it only starts the last one for me as well.
@ryexley @robertklep I'll take a look this weekend.
I mentioned remy in a comment regarding this issue in nodemon itself, so hopefully it'll get resolved soon.
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 thanks, Remy, if you make a branch on nodemon for this issue I'll pull it and try to help out.
I've also noticed that I have to run node app.js
in another tab even if gulp nodemon
is running in one already.
@remy could this be fixed by running nodemon as a child process?
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.
@remy any updated on this in nodemon 1.3.0? I'm getting ready to publish a new version of gulp-nodemon to npm.
@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 need any help? I don't start school for three weeks so I've got a bit of free time on my hands.
Any update on this issue?
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)
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
so.. no fix for a year :(
@BlueHotDog so.. no pr for a year :(
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.
@JacksonGariety @remy any progress on this? have 4 tasks each for a different app. running just runs the last one 4 times...
I need that!
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.
Saw this on stackoverflow: http://stackoverflow.com/questions/34102947/gulp-run-multiple-node-scripts-in-parallel
Maybe this does the job?
@remy Anything we can do to help this get along? Anyone running microservices would be very happy I'm sure!
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 .
Is this really still a thing?
@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"" }
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.
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.