Don't use recursion for things that can be done with loops. Recursion has a considerable performance gap compared to loops.
There are only a few versions of node.js that have tail recursion optimization, and they need to be turned on by flag. The latest version does not (http://node.green/ ). The maximum call stack size for function calls is more than 10,000 value. In addition, tail recursion optimization in ES6 requires return.
Use Stream as much as possible to read large files, you can specify the length of the block, and it will not block the event loop all the time.
If you must use recursion to realize the logic, use
process.nextTick(func)to transfer the depth of recursion from call stack to task queue .
In addition to code optimization, the value that can be stored by local variables outside the loop does not need to be read in the loop with function calls.
Processing large files with node.js