I am new to Node.js and am currently questioning its reliability.
Based on what I\'ve seen so far, there seems to be a major flaw: any uncaught error/exceptions crashes
An uncaught exception will, if not caught, crash the server. Something like calling a misspelled function. I use process.on('uncaughtException')
to capture such exceptions. If you use this then, yes, the error sent to process.on('uncaughtException')
is less informative.
I usually include a module like nomnom to allow for command-line flags. I include one called --exceptions
which, when set, bypasses process.on('uncaughtException')
. Basically, if I see that uncaught exceptions are happening then I, in development, start up the app with --exceptions
so that when that error is raised it will not be captured, which causes Node to spit out the stack trace and then die. This tells you what line it happened on, and in what file.
Capturing the exceptions is one way to deal with it. But, like you said, that means that if an error happens it may result in users not receiving responses, et cetera. I would actually recommend letting the error crash the server. (I use process.on('uncaughtException')
in apps, not webservers). And using forever. The fact is that it is likely better for the webserver to crash and then expose what you need to fix.
Let's say you used PHP instead of Node. PHP does not abruptly crash the server (since it doesn't really serve). It spits out really ugly errors. Sure, it doesn't result in a whole server going down and then having to come back up. Nobody wants their clients to have any downtime. But it also means that a problem will persist and will be less noticeable. We've all seen sites that have said errors, and they don't get patched very fast. If such a bug were to take everything down for one small blip (which honestly its not all that bad in the larger picture) then it would surely call attention to itself. You would see it happen and would track that bug down.
The fact is that bugs will exist in any system, independent of language or platform. And it is arguably better for them to be fatal in order for you to know they happened. And over time it causes you to become more aware of how these error occur. I don't know about you, but I know a lot of PHP devs who make the same common mistakes time after time.