MaiaVictor
MaiaVictor

Reputation: 53047

What's the right way to quit node.js after you've started a server?

I'm developing a server-side node.js application. The problem is, after the server is started using sudo node myfile.js (without sudo it can't access port 80), I have no way to stop it except from using sudo killall node from another command prompt window, which seems wrong because it's laborous and won't activate the event process.on("exit",callback).

Upvotes: 2

Views: 137

Answers (2)

aaaaaaaaaaaa
aaaaaaaaaaaa

Reputation: 3700

For testing you can put a kill-switch in your program, like:

if(req.url=="/shutdown"){
    res.end("Shutting down server.");
    process.exit(0);
}

Then you just have to visit http://localhost/shutdown in order to shut down the server. You could even make an url that also launch a new instance for you, just don't forget to release required resources like files and the port in use first.

Upvotes: 1

StephShelley
StephShelley

Reputation: 114

Adding -9 to kill should solve the problem.

ps aux | grep node
kill -9 PID

Upvotes: 0

Related Questions