[英]Can I run a function when I quit my Node App?
I'm working on a project for school in Node.js on a Raspberry Pi.我正在 Node.js 在 Raspberry Pi 上为学校做一个项目。 I have a script that is running and will run for long periods of time controlling some LEDs.
我有一个正在运行的脚本,它将长时间运行以控制某些 LED。 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)?
有没有办法在我退出程序时运行 function 以关闭我正在使用的所有 LED(停止为 GPIO 供电)?
You can handle the SIGINT
(CTRL-C) signal.您可以处理
SIGINT
(CTRL-C) 信号。 Something like:就像是:
function cleanup() {
// do clean up here
console.log("clean up");
}
process.on("SIGINT", () => {
cleanup();
process.exit(0);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.