Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop NodeJS remotely

I'm working on a NodeJS project where a PHP server will have control over starting and stopping a NodeJS socket server. The server will be started by a remote call via PHP however I am unsure of how to go about stopping a remote NodeJS server, as all answers I have found simply tell me to hit CTRL-C, which is not an option in this case. Does anyone know how to cause an end event in a tidy manner? Is there an event that can fine or is the best I can do to throw an exception?

like image 393
blackbourna Avatar asked Mar 12 '26 14:03

blackbourna


2 Answers

You could always expose a route that calls process.exit();

Node API Docs: process.exit

like image 100
Wes Johnson Avatar answered Mar 14 '26 03:03

Wes Johnson


I'd setup a kickstart script for your nodejs app in /etc/init.d then [start|reset|stop] from the command line. If it's on a remote machine you should look into your php app using passwordless SSH to start/stop remotely.

like image 20
binarycleric Avatar answered Mar 14 '26 04:03

binarycleric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!