Node.js
- Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser.
- Node.js represents a “JavaScript everywhere” paradigm, unifying web-application development around a single programming language, rather than different languages for server- and client-side scripts.
Multi-Thread
- Traditional Web Application follows “Multi-Threaded Request-Response” model.
- Client sends request to the server, then server do some processing based on clients request, prepare response and send it back to the client.
- This model uses HTTP protocol. As HTTP is a Stateless Protocol, this Request/Response model is also Stateless Model.
Single-Thread Event Loop
- Node.JS follows Single Threaded with Event Loop Model and Process model mainly based on Javascript Event based model with Javascript callback mechanism.
- As Node.JS follows this architecture, it can handle more and more concurrent client requests very easily.
- The below digram shows how single thread works, nor Node.js worsk. Event loop in Node.js is much more complcated. About the event loop will be next chepter.
Node JS Advantages
- Handling more and more concurrent client’s request is very easy.
- Even though our Node JS Application receives more and more Concurrent client requests, there is no need of creating more and more threads, because of Event loop.
- Node JS application uses less Threads so that it can utilize only less resources or memory