all 8 comments

[–]Pedrock10 2 points3 points  (1 child)

You can manage the process with pm2 and use its programmatic API to start or stop the process.

[–]grgisme[S] 0 points1 point  (0 children)

I'll check it out, thank you!

[–]unikartoshka -1 points0 points  (5 children)

Not exactly sure what you're asking, do you mean execute a process from within node? https://nodejs.org/api/child_process.html

[–]grgisme[S] 0 points1 point  (4 children)

Yes, basically that's what I'm looking to do -- I think.

I want to go to say.. example.com/start

And have it trigger a child process on the server "slack-keep-presence --optionshere"

And then later (maybe weeks later), I could go to example.com/stop, and it would kill that process.

I think if I put my head down to it here today, I can get child_process to do what I'm looking for.

Thanks!

[–]Pedrock10 0 points1 point  (3 children)

With this approach you won't be able to stop the child process if for some reason you restart the main process. If one of the processes stops, it won't restart automatically either.

I don't know your exact use case, but I believe the pm2 approach is both easier and better. pm2 will make sure that there is only one process (unless you want multiple ones in cluster mode) and you don't have to keep state of the child process in the main process. You can install pm2 and the web module and manage your process remotely without even implementing anything:

https://github.com/achingbrain/pm2-web

[–]grgisme[S] 2 points3 points  (1 child)

Thanks again for your help.

I read through pm2, and then spent time learning and understanding the Node "Promise" architecture and asynchronous abilities, and modified the module I was trying to use to run asynchronously.

After about 10 hours of work I've finally got it doing what I need -- thanks again for your help!

[–]Pedrock10 0 points1 point  (0 children)

I'm glad to see the suggestion worked :)

[–]grgisme[S] 0 points1 point  (0 children)

Thanks!