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).

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.

Adding -9 to kill should solve the problem.

ps aux | grep node
kill -9 PID