I'm working on a project for school in Node.js on a Raspberry Pi. I have a script that is running and will run for long periods of time controlling some LEDs. Is there a way that I can run a function when I quit the program to turn off all the LEDs I'm using (Stop power to the GPIO)?
You can handle the SIGINT (CTRL-C) signal. Something like:
function cleanup() {
// do clean up here
console.log("clean up");
}
process.on("SIGINT", () => {
cleanup();
process.exit(0);
});