Quick start guide to Node.Js: Part-1

Devanshu Tiwari
3 min readAug 30, 2021

What is Node.Js?

It’s a runtime Environment for Javascript which lets you run Javascript code outside the browser environment.
But, when we already have options like asp.net, django, rails etc, why do we need NodeJs?

Let’s find out why…

Why Node.Js?

  1. Easy to learn
  2. Superfast and highly scalable
  3. Less code, Javascript everywhere (A frontend JavaScript developer can easily learn Backend, in less time)
  4. It has npm, a large ecosystem of open source libraries.

How does it work?

Every browser has a Javascript engine that converts Javascript to machine code. E.g. V8 -Chrome, Chakra-Internet Ecplorer, FireFox- SpiderMonkey. That is why sometimes Js code may behave differently in different browsers. What this means is that we can only execute Javascript code inside our Browsers. This was the reality until in 2009, Ryan Dahl came up with an excellent idea to take out Javascript outside the browser. So he embedded Chrome’s V8 engine inside a C++ program and called it Node.Js. This gave Javascript capability to use various objects that earlier were not allowed by browsers due to security issues. With Node.js, we can access file system of a machine, OS module, path module, http module etc.

Where is it being Used?

Big organisations like NASA, PayPal, Netflix, Uber, Trello, Medium, eBay etc to name a few are all using Node.Js to build fast, scalable and robust products.

Is it Non-blocking and Asynchronous?

Imagine you are in a Pizza shop, standing in a queue to order your favourite variant. But wait, in this Pizza shop, they have a peculiar synchronous order policy! The guy at the counter will take your Pizza-order only when the customer before you gets his Pizza, finishes it and leaves the shop. All that time in between he is sitting idle, maybe watcing some random tiktok videos!
Getting tired of complaints the manager decides to hire new counter guys. But the Policy is still the same- “take new order only when previous customer has finished eating and left the shop!”. Anyways, they still offfer delicious pizzas so they start receiving huge volumes of customers and as you might have guessed they have to wait and wait! Now if the Pizza shop is our application and the counter guy the thread of execution. Our application will need more threads to serve new requests, which means the cost of resources will go up. This is quite the case with synchronous-blocking code.

Normally, when you go to a Pizza shop, after placing the order, they give you a token, and you immediately move out of queue so that the guy after you can place his order. So, even when our counter guy can handle one order at a time, he is not going to sit idle in between taking order and its fulfilment. There’s a buzzer(event-loop in case of Node.Js) which signals the counter guy that the previous order is ready to be delivered. This is how asynchronous -non-blocking code works.
So the answer to the above question is, yes!

Node.Js is a non-blocking and asynchronous runtime environment. It uses full advantage of V8 and event-loop to run things asynchronously making it blazing fast and highly scalable.

This makes it great choice for building I/O intensive applications that require a lot of disk /network access.

What next?

Lets start working with node. To start we need to have Node.Js installed on our system. Go to https://nodejs.org/en/ and install the latest release (LTS).
In next Article, we will see some interesting modules in Node.Js
Link to the next Article: Quick start guide to Node.js: Part-2

--

--

Devanshu Tiwari

If you can’t explain it simply, you don’t understand it well enough