title: nodejs/Mac and open files limit
body: <p>I have written a program that recursively reads files in one directory, modifies them and writes them into another directory. Everytime I run that program, it croakes after a couple of hundred iterations. I just run it again, and it seems to complete the task.</p>
  
  <p>Either nodejs or Mac OS X or, most likely, nodejs-on-Mac-OS-X, seems to have some kind of limit on the number of files that can be opened at one time. Searching around, I see that a solution is to use something like <code>ulimit -n 10480</code> and all will be well. Is that the right way? Instinctively, I'd rather not tinker with my system settings and rather modify my program to work within the limits.</p>
  
  <p>An observation: Earlier I used to use Perl to do the task I've described above, and I never had a problem. I am assuming it was because I was opening, transforming, then closing the file, and then moving along. In nodejs, using <code>async</code> mode, I have no way of closing a file <em>before</em> going on to the next file. If I do the task in <code>sync</code> mode, it works fine.</p>