Illustrated Node.JS

Introduction

If you are a regular on C# Corner then you must have seen Node.js many times in the articles and every time you wonder what exactly it is.

According to the Wikipedia:

Node.js is an open source, cross-platform runtime environment for server-side and networking applications written in JavaScript. Node.js provides an event driven architecture and non-blocking I/O API that optimizes an application's throughout and scalability.

node js

I understand that the entire context is quite high-level, but I will try to explain every single bit of this.

What Node.js is exactly

Node.js is a runtime system for creating server-side applications. It works under Chrome's engine to execute code. If I may be specific, it uses the Google V8 JavaScript engine.

And, Node assembles the Google V8 engine along with the libuv platform, abstraction layer and core library.

Node.js really shines when you want to create real-time web applications with push capability.

If you go around the web, you will get a few jargons related to node.js.

  • Non-Blocking
  • Event Driven I/O Paradigm

Here, we have two heavy words Non-Blocking and Event-Driven.

So, the Asynchronous Model is just another way of saying Non-Blocking model. In the asynchronous programming model open/read/write operations on a device doesn't block the calling thread. And, all the threads are on a process without any intervention. That's why they say it is "Non-Blocking".

History

Now, if we look at the history. We will then describe Ryan Dahl who first published it for Linux in 2009. In June 2011, Microsoft partnered with Joyent (the company sponsoring NodeJs) to create a native Windows version of Nodejs.

Ryan Dahl

What makes Node.Js different from the conventional way

So in the conventional model, every time the client's PC makes a request and the web server treats it as an individual request and processes every individual request and then sends a response. Over 20 years, the web technology is using this methodology. In spite of this, we have Flash and Java applets but they are sandboxed under something. So, they use their own socket. Usually, they wait for the resource if someone is using it.

clients PC

But, when NodeJs is single-threaded and non-blocking (asynchronous) then that allows thousands of concurrent connections without any lag. Just because of this, many Chat Web apps and APIs are scripted in node. And because it is easy in scaling and can handle huge requests.

asynchronous

Popular Modules of NPM

Node Package Manager is an online module repository (kind of Play Store for Node module) that allow you to use publically available and reusable modules with version and dependenciy management.

Popular Modules of NPM

Popular modules are:

  • Express.js
  • Connect
  • Socket.io
  • Jade
  • Mongodb
  • Redis
  • Coffee-script
  • Underscore

Reference