Node.js · Senior · Question 48 of 75
A Node.js process doesn't exit after the main script finishes. What's the usual reason?
- 1
process.exitmust always be called at the end - 2Node.js waits for the garbage collector
- ✓Correct answer: Something still holds the event loop open: an open server, socket, timer, DB pool or a pending child process
Explanation
Close pools and servers explicitly. process.getActiveResourcesInfo() lists what keeps the loop alive, and unref() lets background timers not hold it.