Introduction to Node JS – Node.js Basics

Filed Under: Node.js

We are going to deliver a sequence of posts on “How to develop Applications using Node JS, Express JS, Angular JS, Mongo DB, Redis, and RESTful WebServices“.

We will discuss all these posts on Windows Environment only. There is no much difference in Node JS Platform installation and developing applications in other OS Environments.

In this post, we are going to discuss about some basics of Node JS Platform.

  1. What is Node JS?
  2. What is NOT Node JS?
  3. Features of Node JS
  4. Advantages of Node JS
  5. Limitations of Node JS
  6. Who uses Node JS Platform?
  7. Node JS Applications

What is Node JS?

Node JS is an Open Source Java Script Platform used to develop fast and scalable server-side and networking applications very easily.

Google’s V8 Engine is an Open Source JavaScript Engine for the Chrome Web browser. V8 Engine is completely written in C++ Language.

Ryan Dahl is a big fan of “Google’s Gmail”. He was impressed by Gmail performance and started created new Platform.

Ryan Dahl has developed a Server-Side Platform “Node JS” in 2009 on top of Google’s V8 Engine. That means Node JS applications run on V8 Engine.

Unlike some UI Frameworks for example Angular JS, use to write Client-side JavaScript, Node JS Platform is used to write Server-side JavaScript.

We can run Node JS applications on most of the OS Platforms like Windows, Linux, Mac etc.

Official Website for Node JS Platform: https://nodejs.org/en/

What is NOT Node JS?

Node JS is a Platform. It is not a Framework or Web Framework. It is not a Language.

It is a Platform which contains thousands of thousands of modules to develop wide variety of applications. We can install base Node JS Platform and update all your application required modules very easily.

Node JS “Module” is also known as Package. Now onwards, when we refer Module means Node JS Package.

Node JS is not for Multi-Threaded applications. It follows Single Thread with Event Loop architecture. If you don’t know what is “Even Loop” architecture, don’t get tense at this moment. We will discuss on “What is Event Loop and How Node JS deals with multiple requests” in coming posts.

We will discuss how to setup Node JS Base Platform and how to add/install required modules at required time in coming posts.

Features of Node JS

  • Modularity

    Major advantage of Node JS Platform is that it’s modularity. Each and every functionality is divided and implemented as a separate module or package. When we install Node JS Platform, by default it installs only few modules. If our application requires other modules, then we can easily install and configure then at any point of our application development phases.

    Node JS has thousands of thousands modules. Some modules were developed by Node JS Community and some were by Third-party Clients. We will discuss and provide some examples about these modules in coming posts.

    While writing this post, Node JS Platform supports the following number of packages.
    NodeJS-Packages

    We can check this updates on its official website: https://www.npmjs.com/

    Some of the Node JS Modules are written in Java Script and some are in C/C++ Language. It’s 40% modules are written in JS and 60% modules are written C/C++.

  • Express JS

    Node JS is used to develop Server-side Java Script. It also contains a separate module for Web Application Framework i.e. Express JS.

  • Non-blocking or Asynchronous IO

    Node JS supports Non-blocking IO i.e. it uses Asynchronous IO Model to interact with File system or to do Socket communication or network communication.

    Asynchronous IO Model means if IO processing is taking more time, then it permits other processing to continue before the transmission has finished.

    Java Developers are very much familiar about Blocking IO and Non-Blocking IO. Java IO package follows Blocking IO or Synchronous IO Architecture whereas Java NIO 2 follows Non-Blocking IO or Asynchronous IO Architecture.

  • Event-Driven Asynchronous Platform
    Node JS Platform follows Even-Driven Loop architecture to interact or handle requests. We will discuss in details about “Even-Drive Loop” in coming posts.
  • MongoDB Wrappers API
    Node JS platform contains a separate module to integrate MongoDB No SQL database with applications. It provides a MongoDB wrapper API.

    We can use this API to write JavaScript easily to interact with MongoDB database. Node JS-mongodb module uses Mongoose to interact with MongoDB database.

  • Redis Client Library API

    Node JS platform contains a separate module to integrate Redis No SQL database with applications. It provides a Redis wrapper API. We can use this API to write JavaScript easily to interact with Redis database.

  • Jade Template Engine

    Node JS platform supports many template engines to write HTML. Default template engine supported by Node JS is “Jade”.
    Jade is a whitespace-sensitive template engine for developing HTML applications very easily.

    We can write template pages once and reuse them very easily to reduce development time. We will discuss how to install and write Jade templates in a separate post.

  • Web Server

    We can develop and use HTTP Web Server within no time. We need to use http package to implement Web Server. We will discuss one post on how to install http package and develop a Web Server.

  • Better Socket API

    Node JS Platform provides very good Socket Module API to develop Real-time, Multi-User Chat and Multi-Player Gaming Applications very easily. It supports Unix Socket programming like pipe().

Advantages of Node JS

  • One Language and One Data Format
    We need to use one and only one language to write whole applications i.e. Java Script. We need to code all layers from UI to Controller to Business Layer to Persistence Layer (From Front-End to Back-End) in Java Script only.

    All layers from Front-End to Back-End support same Data Format i.e. JSON (Java Script Object Notation). UI Layer Angular JS Supports JSON Format, Server-Side Scripts written in Express JS supports JSON Format and Back-end MongoDB NO SQL supports same JSON Format.

  • Open Source

    Node JS is Open Source Module. It provides many modules for free to use in our applications.

  • Highly Scalable

    To improve our application performance, we will scale our infrastructure. There are two ways to scale any application:

    1. Horizontal Scaling
    2. Vertical Scaling

    Vertical Scalability means adding more resources to a single node. Horizontal Scalability means adding more nodes to a system.

    Node JS uses Horizontal Scaling instead of Vertical Scaling to our applications. It’s consistent with today’s Cloud Technology trend.

  • Better Performance and Low Latency

    I/O operations often blocks our application because it can take a long time to read a big file, or make a large query against a database, or wait for any stream of data to fully transmit.

    As Node JS follows Non-Blocking IO architecture and also uses only JavaScript to develop entire application, we can achieve better performance and low latency.

    If we develop our UI and Data Intensive applications by using MEAN Stack, we can achieve very high performance. MEAN Stands for MongoDB, Express JS, Angular JS and Node JS.

  • Caching Modules

    Node JS Modules are cached once they are loaded into application for first time. Multiple calls to load a module may not cause the module code to be executed multiple times.

  • Less Problems with Concurrency
    Node JS does not follow Multi-Thread architecture. It follows Single-Thread with Event Loop Architecture. It serves any number of requests without any issues.
    Node JS does NOT need to handle pooling of requests to a set of threads. That’s why it has less overhead to handle multiple requests concurrently.
  • Easy to Extend and Lightweight
    We can install only required modules and use them to develop applications. Whenever we need to add new feature or module, we can easily extend it.
    By following this approach, we can also achieve very light-weight nature into our applications.
  • Faster Development and Easy to Maintain
    As Node JS Platform had already provided support for many modules, we can use them and develop wide variety of applications within no time. We can develop and maintain Node JS applications very easily.
  • REST API
    Node JS Platform supports developing RESTful Web Services API very easily.
  • Many Development Frameworks and Tools
    We can get many development tools like IDE and UI Frameworks to develop Node JS applications very easily.
  • Active Development Community
    Node JS Development Community is very active in adding new modules or packages to existing modules to support wide variety of applications development.
  • Unit Testing
    In Node JS applications, we need to write whole code in Java Script. Today we have many Java Script Unit Testing frameworks and tools like Jasmin Framework.
  • Streaming Data
    We can easily develop Streaming-based data applications by using Node JS.
  • Creating Servers
    Node JS Platform has some built-in API to develop or create HTTP Server, DNS Server, TCP Server etc very easily or quickly.
  • It can handle thousands of concurrent connections with minimal overhead (CPU/Memory) on a single process
  • Easy Module Loading process
    It is very easy to load required Node JS Modules into Node JS Applications. We just need to use require() statement in our application. It is similar to “import” statement in Java Programming language. We will discuss about require() in detail with some examples in coming posts.

Limitations of Node JS

  • It does NOT support Multi-threading programming.
  • It does support for Computational Intensive Tasks. Node JS struggles in handling of very high computational intensive tasks, because whenever it does something long running task, it will queue all remaining incoming requests, because it follows Single-Thread Architecture with Event Loop.
  • Don’t use Node JS for Blocking/Synchronous and CPU-intensive tasks.
  • Unstable API – Node JS is still in Beta stage and most of its modules are in unstable state. It’s not ready for Production or Live Systems.
  • Who uses Node JS Platform

    Now-a-Days many people are using Node JS Platform to develop and maintain their applications. Some of the popular companies who are using Node JS Platform are;

    • DOW JONES
    • When-To-Manage
    • Linkedin
    • MicroSoft
    • Twelephone (It is a service for making calls right from Twitter account)
    • Yahoo
    • PayPal
    • eBay
    • STRONGLoop
    • Wallmart
    • Groupon
    • SAP
    • PINT Web Platform (PWP)
    • Cloud9 IDE
    • Dropbox
    • ZingChart
    • Chess (It is an online game available on facebook.com)

    Node JS Applications

    We can use Node JS Platform to develop the following kind of applications.

    • Network applications
    • Asynchronous Events
    • Intelligent Networking Proxies
    • Proxy Server
    • Multiplayer Game Applications
    • Data Intensive Real-time applications
    • Web Applications
    • High Definition(HD) Voice and Video Communications
    • File Uploading Tools
    • Process Monitoring Tools
    • Many-To-Many Instant Chatting Applications
    • Many-To-Many Instant Messing Applications
    • HTTP Web Server
    • Real-time Logistics Systems
    • Streaming Server
    • High Concurrency Applications
    • Communication Hubs
    • Coordinators
    • DNS Server
    • Static File Server
    • TCP Server
    • Stock-Trading Dashboard

    In coming post, we will discuss about “How to setup Node JS Base Platform” and also about “Node JS Components“.

    Comments

    1. Manish kumar says:

      Best Article and Awsome and very easy Explanation, Thanks man

    2. Guoquan says:

      Awesome elaboration for Node JS concept, it is very helpful for the developer to build to correct concept about Node JS, thanks.

    3. Santhosh says:

      Awesome post. it gave me a great start. Appreciated your work.

    4. Polinaidu Tentu says:

      Excellent Explanation

    5. Kapil Waghe says:

      This is the perfect! and the best! article on Node JS. This is my first time with it and after reading this blog completely I think I and Node JS are close friends. Thanks Rambabu Posa (y)

      1. Rambabu says:

        Thank you so much. Please read all my posts and give me your suggestions.

        1. rajjanwa says:

          Hi Thanks for all posts regarding scala and js. All posts are really helpful for us. can you post the example of REST data to be fetched by front end based submit and display it on another web page?

    6. vimal says:

      this post is awesome ..where i can find the other post or next topics

      1. Rambabu says:

        Thank you. Get all my posts at https://www.journaldev.com/dev/node-js. Use “Older Posts” or “Newer Posts” links bottom of this page to access all my posts on Node JS.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    close
    Generic selectors
    Exact matches only
    Search in title
    Search in content
    Search in posts
    Search in pages