How do I pause a NodeJS script?

I created a script in Javascript using Node.js to scrape some data from a website overnight. We'll, I'm at 67% and it's going to take about 5-6 more hours to finish. But I have enough data at the moment that I'd like to stop it.

Is there a way to pause script execution into a Node REPL session and inspect the variables? Or something similar?

(I'm scraping data into an array).

Thanks

You can put Node in debug mode (which can pause execution) by sending a USR1 signal to it. Check out https://github.com/dannycoates/node-inspector/

  1. find the PID of your node process: ps -x | grep node
  2. send a USR1 signal to the process: kill -s USR1 $pid
  3. start node-inspector: node-inspector &
  4. open a browser on http://localhost:8080/debug?port=5858
  5. click pause in the top right corner