Question

In the parent process, I have started the tiny-lr(livereload) server, followed by spawing a child process which looks for changes to the css files. how to pass on the livereload server to the child process or is it possible to query for the livereload server that is currently running in the child process so that I don't create it again getting an already in use error for the port.

the same case with node http server. can I know if the server is already running and use that instead of creating new one.

Was it helpful?

Solution

is it possible to query for the livereload - it is possible and may be implemented in more than one way.

  1. Use stdout/stdin to communicate with the child process. For detailed description look HERE. Basically you can send messages from one process to the other and reply to them.

  2. Use http.request to check if the port is in use.

  3. You can use a file: the process with the server keeps the file open in the write mode - the content of the file stores the port on which the server runs (if needed).

  4. You can use sockets for inter-process communication, as well.

Basically, none of the above guarantees 100% confidentiality, so you have to try/catch for errors anyway: the server may die just after your check, but before you wanted to do something with it.

how to pass on the livereload server to the child process - if you mean sharing an object between different process that it is for sure out of question; if you mean changing the ownership of the object that I am some 99,99% sure it is not possible neither.

What is the problem with having just one process responsible for running the server? And why not to use, let say, forever to take care of running and restarting the server, if needed?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top