Getting Started With NodeJS

Introduction
 
In this article, I will explain to you what Node.JS is, what are the advantages and limitations of Node.JS, NodeJS architechture and installation. 
 
Node JS
  • NodeJS is a Server side runtime environment, which is used to develop the Web Applications, which are similar to ASP.NET,JSP, PHP etc.
  • Open source.
  • Cross platform support framework.
  • NodeJS is based on Google's V8 engine and libuv.
  • NodeJS is developed by Ryan Dhal and his team in 2009 at Joyent inc.
Advantages
  • Open Source
    NodeJS is open source, which means it's free and you do not need to purchase any licence for it. NodeJS has lots of modules, which are completely open source.  

  • Scalable
    NodeJS Application can be scalable in two ways. Horizontally means you can add some nodes to your existing system and Vertically means on the single node; you can add more resources like memory etc.

  • Reusability
    NodeJS is reusable because the front end side and client end side use JavaScript code, so we can reuse our modules on the client side as well as on the Server side.

  • Better Performance
    Node JS input-output operations are non-blocking, so the performance is also good. NodeJS supports caching, so in the first request ; it caches JavaScript module on the Server side and when the next request occurs, it fetched the module from cache. 

  • Asynchronous I/O
    It's build to handle an asynchronous input output from the ground up. Node can handle large volumes of requests asynchronously.  For fast execution, it uses Event loop, which is the real magic behind it, which I will explain in the next article. 

  • JavaScript
    Node uses JavaScript as a programming language for the back-end and front end. 

  • Community Support
    Node.js has a wide community of developers, and lots of node modules or packages are freely available on the internet, which has produced many excellent modules to add additional capabilities to Node.js Applications.
Architecture

NodeJS is divided into two main components, which are Google's V8 Engine and Libuv. 
 
  • Google's V8 Engine
    This is an open source, JIT(Just In Time) compiler, which is written in C++. This is a high performance JavaScript engine, which is used in Google Chrome. This engine compiles JavaScript code directly into an assembly language code, which is ready for the execution by avoiding any intermediary representation like tokens opcodes, which are further interpreted. Google's V8 engine is again further divided into three majors components, which are described below.

    • Compiler
      This is responsible for compiling JavaScript code.

    • Optimizer
      This is also known as Crankshaft. This optimizer optimizes JavaScript code during the compilation time. For that it generates AST (Abstract Syntax Tree), followed by generated AST, using JavaScript code. Subsequently, AST is translated again into SSA (Static Single Assignment).

    • Garbage Collector
      V8 engine creates a heap to track JavaScript object. Garbage collector checks the memory, where an object has been dead. If any object has been dead, it assigns the newly created object to the dead object location. Similarly, V8 engine manages the memory.  

  • Libuv
    According to Libuv Document, "Libuv is a multiplatform support library with a focus on asynchronous I/O".  Libuv is the core library for Nodejs, which is used for an asynchronous input output operation, written in C/C++. which are as follows.

    • Thread Pool
    • Event loop
    • Async I/O
    • C-ares(Async-DNS resolution) 
    • http parser
    • Open SSL
    • Zlib
    • Asynchronous TCP and UDP sockets
    • File System
    • Signal handling  and many more

                                             NodeJS Architecture
 
 
NodeJS Installation

Follow the steps mentioned below to install nodejs.
  • Download NodeJS setup from NodeJS Website.
  • Run Installer. 
  • Restart your machine.  
Limitations

NodeJS has some limitations, which are as follows.
  • Doesn't support multi threading. 
  • Can't perform the computational tasks. 
  • Can't perform such types of operations, which take time to execute; otherwise all the upcoming requests will be in the event queue and will wait for the execution.
Note

NodeJS is not a JavaScript library, which is just a platform where we can execute our JavaScript code.


Similar Articles