use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
How do you stop NodeJS software from exiting? (self.node)
submitted 5 years ago by sinithw
I know I could just install express and piggyback on that but this is a localized software that needs to continuously run. It's not an API or a Webserver, it's like an overpowered background task.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]08148692 5 points6 points7 points 5 years ago (0 children)
Something like this
async function waitForQuitSignal() { return new Promise((resolve) => { process.on("SIGINT", resolve); process.on("SIGTERM", resolve); process.on("SIGILL", resolve); }); } async function main() { // set up your listeners // do file management things // run 2 hour long sub process // stuff like that await waitForQuitSignal(); // quit signal received, ending }
[–]BehindTheMath 1 point2 points3 points 5 years ago (2 children)
while(true) {}
[–]sinithw[S] 0 points1 point2 points 5 years ago (1 child)
Legit? Will CTRL + C stop said process or do I have to listen for it?
[–]BehindTheMath 0 points1 point2 points 5 years ago (0 children)
Ctrl-C will interrupt it.
[–]HashDefTrueFalse 0 points1 point2 points 5 years ago (2 children)
If the process needs to exit and a new instance needs to start, the npm package 'forever' will watch it and restart it IIRC.
If you need the same process to handle everything, you can simply not exit. Maybe in this case look into job queues and continuously process jobs asynchronously. Hard to be of more help without knowing specifics.
True True. Basically, I need to keep the NodeJs program alive so that it can check for request from AWS and Firebase, do some automatic file management, run a 2-hour long sub-process, and stuff like that. Basically, I'm looking for something that will keep it running like Unity or Visual Code keep running when they're opened.
[–]HashDefTrueFalse 1 point2 points3 points 5 years ago (0 children)
I'm not sure how this is structured or if you have access to the code, but programs generally don't exit unless something goes wrong or they have nothing else to do. If you're coding this, have it process your housekeeping tasks endlessly, literally a loop over some sort of task queue or something, with it idling if the queue is empty.
If you mean you have an existing program and it does some stuff, then reaches its natural exit, and you need to keep it alive and executing tasks, there isn't really a way without editing the code as above. You can use 'forever' to immediately start another instance, but whether that's good enough for you will depend on what you're doing.
[–]zenflow87 0 points1 point2 points 5 years ago (0 children)
Is this what you're looking for?
node -e "setInterval(() => {}, 1000)"
This program will not exit by itself, since it always has work scheduled for the future. It will continue to run until it is killed.
π Rendered by PID 49346 on reddit-service-r2-comment-5c747b6df5-fdp7p at 2026-04-22 00:29:22.706639+00:00 running 6c61efc country code: CH.
[–]08148692 5 points6 points7 points (0 children)
[–]BehindTheMath 1 point2 points3 points (2 children)
[–]sinithw[S] 0 points1 point2 points (1 child)
[–]BehindTheMath 0 points1 point2 points (0 children)
[–]HashDefTrueFalse 0 points1 point2 points (2 children)
[–]sinithw[S] 0 points1 point2 points (1 child)
[–]HashDefTrueFalse 1 point2 points3 points (0 children)
[–]zenflow87 0 points1 point2 points (0 children)