Saturday 12 March 2016

Is there any way to make Node.js console programs responsive to user input? I.e., is there any way to have "press Q to quit or P to pause?"

I have a background process running which basically runs through a whole bunch of numbers. It's fizzbuzz, but that's not important. What's important is that if, say, you're doing the numbers 1 - 10000000000, you might want to abort the process before it's done, but keep the numbers you've already calculated.What I'd like to do is set it up so that while the program's running, if the user presses "Q," it'll stop calculating and just write out the last chunk (I process the file in chunks of 10000 at a time); Normally I work on web-based apps, but this is a console-only application so far, and I don't want to download and install Electron just to get the functionality of "addEventListener()"Any thoughts?

Submitted March 13, 2016 at 06:05AM by BrianBoyko

No comments:

Post a Comment