0

I would like to increase the call stack limit for my node process so that I can create, parse and serialize a recursive object that's about 100,000 layers deep. If I had more time, I should represent this in a better format.

But for a quick fix, there is a suggested solution to do something like:

/bin/bash -c "ulimit -s $n; exec /usr/local/bin/node --stack-size=$n app.js"

Are there any repercussions that I need to worry about?

petabyte
  • 1,487
  • 4
  • 15
  • 31

1 Answers1

1

Just use node --stack-size=2048 app.js or any other amount in kbytes. But keep in mind, that this is not a production way. Higher value you'll put - more unstable app could become.

As noted by others, be aware that increasing this value may lead to a segmentation fault. Looking at the bigger picture, increasing stack size may not solve all your issues. When writing recursive functions in node, your best strategy is to write them in a tail-recursive manner, since node supports proper tail calls. This will eliminate stack size overflows.

tarkh
  • 2,424
  • 1
  • 9
  • 12