Introduction to NodeJS, A SSJS: Part I - Components Explained

Since I have been working with JavaScript for the last 2 years, I just wanted to share some thoughts about JavaScript on a server. Most of us (if you are an ASP.Net develper) use JavaScript as a client-side scripting language for just validation and some DOM manipulation.

But we should understand how JavaScript can be used in various ways like on the server or in hardware.

JavaScript could be used on hardware devices like Arduino, Raspberry, Ninja Blocks, Tessel and so on. You can find a good article on JavaScript in devices from sitepoint.

Let us move on to understand how JavaScript is used in a server. There are many JavaScript solutions that run Server Side. To name a few:

SkillJS

NodeJS

Whitebeam

TeaJS

Narwhal

GLUEScript

APE

WakandaDB

MongoDB NoSql DB on Server

CouchDB

We shall learn why NodeJS is more famous among the other JavaScript solutions. To understand NodeJS, we ask questions the What, Why, Where and When on NodeJS.

What NodeJs is

NodeJS is a command-line tool mainly to create network applications but we can even use NodeJS to create a simple general command-line application like Calculator.

From Nodejs.com: “Node.js® is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices”.

As stated in the quote, NodeJS runs on top of Chrome's V8 that is extremely fast. The NodeJS environment uses “libuv”, a C++ library for asynchronous I/O.

Main components of NodeJS

The main components of NodeJs are APIs, a V8 Engine and Libuv.

Libuv Library

Libuv is a multi-platform support library for asynchronous I/O. It was developed for Node.js using C and C++. But it's also used by Mozilla's Rust language, Luvit, Julia, pyuv and others.

This libuv library is the main part for I/O related operations like reading files and interacting with the OS.

You can check it out on GitHub for more information about the libuv library.

V8 Engine

From Google: “V8 is Google's open-source high-performance JavaScript engine, written in C++ and used in Google Chrome, the open source browser from Google. It implements ECMAScript as specified in ECMA-262, 3rd edition and runs on Windows XP and Vista, Mac OS X 10.5+, and Linux systems that use IA-32, ARM or MIPS processors. V8 can run standalone, or can be embedded into any C++ application”.

If you are interested in learning more about the V8 engine, please visit here.

APIs (NodeJS Core Libs)

The NodeJs APIs are nothing but functions to do something upon your request. By default the NodeJS apis are asynchronous in nature but still you can use NodeJS APIs synchronously.

For example, the http module could be used either synchronously or asynchronously.