-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "listening" or "ready" event #832
Comments
Urm...but nodemon doesn't listen. It doesn't even use the |
Mmm, I see. Is there a way then for the app code to interact with Nodemon and decide when to trigger some |
Share your |
Hi, This is the way I wish it could work: // Start server
gulp.task('server', function (cb) {
$.nodemon({
script: serverPath,
watch: serverPath
})
.on('ready', cb);
}); But for now I'm stuck with a less elegant solution: // Start server
gulp.task('server', function (cb) {
$.nodemon({
script: serverPath,
watch: serverPath
})
.on('start', function () {
setTimeout(cb, 500);
});
}); |
@pensierinmusica you can parse stdout and trigger event (call callback) on specific message: gulp.task('server', function (cb) {
const readyMessage = 'server started';
nodemon({
script: serverPath,
watch: serverPath,
stdout: false
})
.on('stdout', function (stdout) {
console.log('server stdout:', stdout.toString());
const isReady = stdout.toString().includes(readyMessage);
if (!isReady) { return; }
cb();
});
}); |
@remy close? :) |
@pensierinmusica for my case I found it useful to simply start browsersync from the server itself. So, |
I am having a similar issue. I reported in Browsersync repo. |
Thanks @vlkosinov and @sandro-pasquali for your suggestions! I ended up adopting a modified version of what @vlkosinov suggests. @sandro-pasquali method also looks nice, but decided to keep the logic of Gulp inside So this is the solution I adopted: gulp.task('server', function (cb) {
$.nodemon({
script: serverPath,
watch: serverPath,
stdout: false
})
.on('stdout', function (mess) {
console.log(mess.toString());
cb();
})
.on('stderr', function (err) {
console.err(err.toString());
});
}); I guess we can close this issue now, thanks everyone! |
Hi @remy!
Would you be so kind to add the
listening
event to nodemon states?You can get it directly from Node: https://nodejs.org/api/net.html#net_event_listening
This is needed for example when using gulp-nodemon, since starting the Node server can be part of multiple tasks and you don't want to run something like browsersync until the server is actually listening.
I tried using the
start
event, but when the browser loads the server is not listening yet, so you get a blank page and need to manually reload, which is annoying.Thanks in advance for adding this!
Cheers
The text was updated successfully, but these errors were encountered: