I am trying to get gulp-livereload
to work with my nodejs server. I am using gulp-nodemon
to restart the server after changes to the files, this works. I am having trouble invoking livereload.reload()
at the correct time.
I am currently invoking livereload.reload()
on the .on('start'...
in my gulpfile.js
(whenever my nodemon starts a script). This works but it takes a few seconds. The reason is when nodemon starts to run the nodejs script it invokes livereload.listen()
before the script has invoked app.listen(port)
, so my browser refreshs without the server being ready.
Is there a way to listen if the nodejs nodemon script has invoked app.listen(port)
or perhaps listen to see if a specific port is being used?
I have fixed the issue with a small sleep but it just feels so wrong and dirty.
Use readable event to monitor stdout of child process.
example:
app.js
Here is a an example of simple and tested livereload solution based on
connect
server andconnect-livereload
andgulp-livereload
plugins if that is of any help: