Node.js is an open-source, cross-platform and single threaded java Script runtime environment.

It is popular tool for almost any kind of projects. 



How Node.js works?

Node applications are highly scalable because of the non-blocking or asynchronous nature of Node.
Asynchronous is like a single thread is used to handle the multiple requests. Node applications are asynchronous by default.

In Node we have single thread to handle all requests. linear request arrives that single thread is used to handle that request.
If need to query a database the thread doesn't have to wait for the database to return the data. while the database is executing our query that thread will be used to serve another client.
When the database prepares the result it puts a message in what we call an event queue. Node is continuously monitoring this queue in the background.
When it finds an event in this queue it will take it out and process it. This kind of architecture makes node ideal for building applications that include a lot of disk or network access. 
can serve more clients without the need to throw in more hardware and that's why node applications are highly scalable.




Node.js dependencies

Libraries
Java script engine[v8 engine]:  A library that takes our Java Script code and executes it. Node.js uses v8 engine. v8 engine was implemented google chrome browser. v8 was written with C++ programming language.

An asynchronous code handler[Lebuv]: A library that implements the node.js event loop and all of the asynchronous behaviors of the platform. Lebuv is a library with c language which a tool that enforces an asynchronous, event-driven style of programming. Its core job is to provide an event loop.


Event Loop

Allows Node.js to perform non-blocking I/O operations-despite the fact that Java Script is single-threaded by offloading operations o the system kernel whenever possible.
It is a loop that looks at all available events and executes them till there isn't anything left. The evet queue is like a to-do list for the thread and event loop is the thread continuously checking this to do list and doing those things until there isn't anything left. If the queue is empty it goes to sleep. But once an event gets into the queue it wakes up and does this thing all over again.





Module

It is a functionality system organized in one file or more. Modules can be reused easily by requiring it.

Module Loader is a tool that import a module to the current process.

Node.js uses CommonJS module system.



Advantages

  • Node.js has opened the doors to JavaScript full stack development, inheriting the merits of JavaScript programming as well as allowing engineers to use its libraries and features.
  • Lightweight JavaScript achieves high performance with fewer lines of code when compared to Java or C.
  • The frontend and backend are easier to keep in sync, because of a single language used on both sides of the application.
  • Node.js is highly scalable and light weight.
  • Node.js is considered fast because of the v8 engine. it's used to compile JavaScript machine code instead of using an interpreter.
  • It is event-based nature makes Node.js highly efficient for real-time apps that require constant data updates, the non-blocking input-output model solves performance issues.


Disadvantages

  • The Event Loop is the main feature of Node.js, and there may be too many callback are running in your code. So Node.js is not also suited for CPU-intensive tasks, if you are doing that it might slow your application.
  • Node.js does not support multi-threaded programming this is the reason why it is only preferred for the lightweight applications (online games ,chat ). If you are using it for heavy applications, your choice is wrong.
  • Node.js API has some consistency issues. Most of the times the new API comes with many backward changes, then the programmers are required to make changes in the code to make it compatible.