Darwin (OS X kernel) has a low limit for file descriptors (256 per process) by default.
When you try to open more file descriptors than this, an exception is thrown.
This is a simple library that allows you to easily raise this limit manually for the running process.
Node.js 0.12 joyent/node@6820054 has a proper fix so you hopefully won't need it for when it's released as stable.
It still requires you to manually invoke something like
launchclt limit maxfiles 10000 10000, otherwise it won't make any difference. You'll have to run this command as a system administrator / root. Do yourself a favor and read the reference. You can't turn the limit higher without invoking it with the right permissions or it'll just silently ignore it. To verify your limit use
launchctl limit maxfiles.
npm install osx-ulimit
require('osx-ulimit').set(); // Defaults to 30000
To get the current ulimit
If not on OSX, the above will be
The threshold should be an integer number with the minimum soft limit of file descriptors you want. Default: 30000.