I have been studying Node.js recently and came across some material on writing simple Node.js based servers. For example, the following.
var express = require(&qu
Assume there is a hotel named Apache Hotel which has a waiter for each customer.
As soon as the customer orders a salad, the waiter goes to the chef and tells him. While the chef prepares the food, the waiter waits. Here,
Chef => File System,
Waiter => Thread,
Customer => Event.
Even when the customer orders water the waiter brings only after serving the salad. The waiter keeps on waiting until the salad is prepared by the chef. This state is referred as blocking state. Even if the hotel grows each customer should have different waiters to serve. This increases the blocking of threads(waiters).
Now, coming to Node Hotel there is only one waiter for all the customers. If first customer orders soup the waiter tells the chef and goes to second customer. After the food is ready the waiter delivers to the customer. Here the customer will not wait. This state is referred as Non-Blocking state. The single waiter(Thread) servers all the customer and makes them happy.
Thus, Node which is a single threaded application is very fast.