In this tutorial, we will discuss about NodeJS, Architecture of NodeJs,
advantage and disadvantage of NodeJS.
- NodeJS Introduction
- NodeJs Architecture
- Advantage of NodeJS
- Disadvantage of NodeJS
NodeJS Introduction
- Ryan Dahl developed Node JS in the year 2009
- NodeJS is free of cost (Open Source) and cross-platform runtime environment for executing JavaScript code outside a
browser.
- NodeJS js is not a programming language. It is a runtime environment.
Node js uses the javascript for the frontend programming interface.
- NodeJS can be runs on various platforms like Windows, Linux, Unix, Mac OS X,
etc.
- If we create a .JS file in our system and want to run that file we can use
node.js. So it provides runtime enviroment.
- NodeJS is commonly used for Backend Social Networking, Sinple page
application, Chat Applications, Data Streaming etc.
- NodeJS runs single threaded, non blocking, asynchronous programming which
is very memory efficient.
- NodeJS eliminates the waiting, and simply continues with the next request.
- There are many companies which use NodeJS like Netflix, NASA,
Trello, PayPal, LinkedIn, Walmart, Uber, Twitter, Yahoo, eBay, GoDaddy.
Google uses NodeJS in its search indexing service.
- Node JS can be described as JavaScript that has been given the
ability to run on the computer, instead of the browser. This is made
possible by the V8 JavaScript runtime engine.
- Node.js is built on the V8 engine of Google. It is the fastest
javascript engine. The V8 engine converts the javascript code into the
machine code, which the computer understands. The result is then generated
and returned to node.js.
- Node.js uses asynchronous programming.
Problem with A Typical Web application
Assigning Independent Threads to Each Request is an Expensive Task. In
technologies like C# and Java, each request is processed with an independent
Thread. The problem with the approach is that Server has Fixed No of Threads in
the Thread Pool. Therefore at any moment of time, Maximum Request processed are
equal to number of Threads in Thread Pool.
NodeJS Architecture
The following diagram show the how NodeJS handle multiple concurrent
request using single-threaded event loop architecture.
Components of the Node.js Architecture:
- Requests - User send the requests to the server can be either blocking (complex
or heavy) or
non-blocking (simple).
- Node.js Server - The Node.js server accepts user requests, processes them and returns results to the users.
- Event Queue - Event Queue is used to store the
incoming client requests and pass them sequentially to the Event Loop.
- Thread Pool - The Thread pool in a Node.js server contains
the threads that are available for performing operations required to process
requests.
- Event Loop - Event Loop receives requests from the Event
Queue and sends out the responses to the clients.
- External Resources - In order to handle blocking client
requests, external resources are used. They can be of any type (
computation, storage,etc).
In the above image,
when the request hits the node server, it will go
to the event loop through the event queue. The event loop will now check whether
the task is heavy, like operations dealing with files or network-related
operations. If the task is heavy it will offload it to the thread pool, where
the thread pool will execute the task separately. it will not block our event
loop, and the event loop can perform all the less complex tasks. So Asynchronous
and Non-blocking of I/O operations features enhance the scalability,
performance, and throughput of Node.js web applications.
Node.js Advantages
- V8 JS engine complies with Javascript code directly into the machine
code that enhance performance for Real-time Applications.
- Easy Scalability for Modern Applications
- Large Community Support to Simplify Development. Nodejs is supported on
Github which makes it super easy and fast to develop and support the
framework.
- Easy to Learn and Quick to Adapt.
- Nodejs use single language on front-end and back-end Javascript.
- Nodejs is compatible with desktop, mobile, and web development for Mac,
Windows, and Linux.
- Nodejs along with npm libraries Boosts development speed
- Helps in Building Cross-Platform Applications
Node.js Disadvantages
- Node.js Reduces performance when handling Heavy or complex Computing
Tasks
- Node.js Asynchronous Programming Model makes it difficult to maintain
code
- High demand with a few Experienced Node.js Developers in the market.
Prev
Next