- Its fast as it has Chrome V8(it helps executing threads faster).
- Its single thread and there is a smart event loop to handle multiple client requests.
- Single thread good as scaling multi threaded app is cumbersome.
- Async and event driven.
- Supports caching.
- Thread and Event pool: The responsibility of the event pool is to build event queues and then process the events one at a time. The responsibility of the thread pool is to ensure that the requests are received and managed by a single thread and then pass them on to the event loop.
- Node binding is used to facilitate communications with external systems. For example, if we want to communicate with HTTP servers, we can use HTTP binding.
- Based on JS event model. It uses JS callback mechanism.
- Buffer Class exist in Node designed to handle raw binary data.
- Each buffer correspond to certain raw memory allocated outside V8. Code Sample 1:
var dbuffer1 = new Buffer(24);
var dbuffer1 = new Buffer("8", "utf-8");
dbuffer1.write("Happy Birthday", "utf-8");
dbuffer2.copy(dbuffer1, 16);
Code Sample 2:
const arr = new Array(2);
arr[0] = 10
arr[1] = 20
//copy array content
const dbuffer1 = Buffer.from(arr);
//shares mem witharr
const dbuffer2 = Buffer.from(arr.buffer);
setImmediate() vs nextTick() vs setTimeout(fn,0)