What is special in Node.js?
The most important and special feature of Node.js as compared with another server is in Node.js it is possible to create real-time websites with push capability. In node.js this real-time web application with push capability acquired by using web sockets. The advantage of it become in general web applications are using stateless-web based on the stateless request-response paradigm, we finally have web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely. This is in stark contrast to the typical web response paradigm, where the client always initiates communication. Additionally, it’s all based on the open web stack (HTML, CSS, and JS) running over the standard port 80.
Lets go to the internals of Node.js. In highlevel view nodeJS is a comblination of 3 building blocks.
libuv is a high-performance multi-platform supported library with a focus on asynchronous I/O. It was primarily developed for use by Node.js and it also using in Luvit, Julia, pyuv and others.
libuv having features like
1. full-featured event loop backed by epoll, kqueue, IOCP, event ports.
2. Asynchronous TCP and UDP sockets
3. Asynchronous DNS resolution
4. Asynchronous file anf file system operations
5. File system events
6. Signal handling
7. IPC with socket sharing using Unix domain sockets or named pipes
8. Thread pool
9. Signal handling
10. High resolution clock
11. Threading and synchronization primitives
JS and C++
How it works and where it use?
The Node.js applications are works like non-blocking, event-driven I/O to remain lightweight and efficient data flow and processing. The Node.js is not suitable for the applications which using CPU-intensive operations. But Node really shines is in building fast, scalable network applications, as it’s capable of handling a huge number of simultaneous connections with high throughput, which equates to high scalability.
In Traditional web applications, it will create a new thread for each request which result, huge use of RAM. But Node.js operates on a single-thread, using non-blocking I/O calls, allowing it to support tens of thousands of concurrent connections
Let's go for a quick calculation. assuming that each thread potentially has an accompanying 2 MB of memory with it, running on a system with 8 GB of RAM puts us at a theoretical maximum of 4000 concurrent connections, plus the cost of context-switching between threads. That’s the scenario you typically deal with in traditional web-serving techniques. By avoiding all that, Node.js achieves scalability levels of over 1M concurrent connections
Also, Node is a single threaded for handling all client requests, it is a potential pitfall of writing Node.js applications because
1. The heavy computation could choke up Node’s single thread and cause problems for all clients (more on this later) as incoming requests would be blocked until said computation was completed.
2. Developers need to be really careful not to allow an exception bubbling up to the core (topmost) Node.js event loop, which will cause the Node.js instance to terminate (effectively crashing the program).
I am using windows machine for my development purpose. So in following steps explains how to install node in a windows machine,
1. Download the .msi installer of node from https://nodejs.org/download/
2. Install it on your local machine.
3. Configure the node.js bin path to your System environment properties