I had been asked to complete a small task using Node JS. And I don’t even know Node JS. Sure, I’d touched it before, but just ‘touched’, cause I never used it.
However, on Thursday (Dec 20th), I started learning Node JS. The plan was to get done and dusted with the task before Christmas.
As of today (Saturday, Dec 22nd), considering the little lot I’ve read and learnt, I am really excited about the possibilities of JavaScript in Node JS runtime.
To my badass Node geeks, I apologize I’m just knowing this. My bad. I’m a lazy being.
Here’s the super gist: Node.JS runs single-threaded and asynchronous programming.
-
Single-threaded.
-
Asynchronous programming.
What? I paused, and re-read. I googled the next question that came to mind: “How does it do that?”
Cause I’m like: Dude! JavaScript used to be ‘always synchronous’. What’s changed?
Turns out that JavaScript achieves the above by using various callback mechanisms — something referred to as a “Non-blocking I/O model”.
This allows I/O operations to continue fetching data over web connections, while JavaScript execution itself can be blocking. Node JS manages all these processes by setting timers for the duration of the operation to avoid blocking. And so on..