I'm new to Swift so to learn I'm trying to create a command line toot, in the code I'm running a node server using Process. The problem here is that when I exit the program the node process is still running and I want to end it whenever I exit the program or when I'm about to exit the program.
import Foundation
let port = "3030"
let process = Process.launchedProcess(launchPath: "/usr/local/bin/node", arguments: ["/path/to/file/index.js"])
print(process.processIdentifier)
I found out how to get the PID of the process but I don't know how to kill it on exit or when I'm about to exit.
Edit
process.terminate() works, but the behavior I want is to keep the program running until it's killed manually (ctrl + c), killing the node process with it. I can keep the program running by using waitUntilExit(), however, using terminate() won't work if I use waitUntilExit().