I am comparatively new to node.js. And I have a question related to it. As far as I understand, node.js use event driven paradigm, so it spawns only a single thread and handles everything asynchronously(event driven fashion). This helps it consuming less resources and handling lots of simultaneous connections.
However, I have one question related to that, since it has only one thread, even a single unhandled exception could crash everything isn't it. Unlike node.js webserver like apache which can use multiple processes to handled multiple connections, even if one process crashes it doesn't matter.
So, I am bit concerned whether node.js is good for that. I am just a beginner. So any insights will be helpful
Node. js applications are prone to all kinds of web application vulnerabilities.
Node. js development has become very popular over the last four years and continues to stand the competition in 2022 making startups worldwide choose it over other available options.
Let's use an analogy to explain this relatively newfangled technology: A record player and ten users:
PHP Multithreaded: 10 record players, each player has one arm+needle, each user has one record player. Each user plays a few notes off their own record player. Unhandled exception, or hissing notes=record player keeps playing until user lifts arm/Process closed. Nobody else can hear it because they have their own record player. And they're wearing headphones.
NodeJS: Single Threaded
One record player, with 10 arm+needles, one for each user, and they're all sharing that one record player. Each user accesses a quick few notes, a process, off the record at the same time. It's asynchronous, everybody gets a piece of the music. An unhandled exception= hissing notes for the one user, only those accessing the same few notes, or same process that throws the exception will hear the hissing too. But that's about it. Everyone else will still hear the sweet music. They still have their own headphones.
K. No more bad analogy.
Here's the solution to your hypothetical problem: In Node.js, you can attach a listener to the `uncaughtException" event. So you can kill the offending process if it would, or could, in the rare event, take down the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With