0% found this document useful (0 votes)
3 views

1. Introduction to NodeJS

Blah blah

Uploaded by

Smoked By Cylien
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

1. Introduction to NodeJS

Blah blah

Uploaded by

Smoked By Cylien
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NodeJS

Table of Content –
1. Introduction to NodeJS.
2. Foundation of NodeJS.
3. Input and Output (I/O)
4. What is NodeJS made of?
5. What is libuv?

1. Introduction to NodeJS –
You must have heard about JavaScript by now. JavaScript is one the most famous
programming language that exists out there. Till now if you have never interacted with
NodeJS then most probably, you must have interacted with JavaScript inside browser. In
browsers there are a lot of functions that are available. For example:

• `document.getElementById()`
• `document.getElementsByClassName()`
• `fetch()`
And all. These functions you must have executed before in JavaScript in order to manipulate
DOM. The thing about JavaScript is that if you will search any of these functions in the
official documentation of JavaScript released by EcmaScript, you will not find any
documents for it. It is because JavaScript in itself is not that powerful that it can also
manipulate things on browser or it can download some data. It is not that powerful.
JavaScript is like any other programming language, it can do bunch of looping, it has
functions, conditionals and all of the basic functions and features.

What happens behind the scene is that, there is a concept of “runtime environment”, if you
know how JavaScript handles asynchronous tasks, you must have been aware of the
concept of runtime. JavaScript runs inside a runtime. The runtime provides a lot of
resources in terms of memory, in terms of architecture, in terms of external functions.
Using these resources, the capabilities of JavaScript enhanced. JavaScript is great, but when
we execute it inside a runtime then the capabilities of JavaScript enhances. JavaScript gets
access to a runtime-based features.
What browsers do? Browsers can actually render HTML for you. So JavaScript gets a
functionality using which it can change the CSS around it, it can manipulate your DOM, it
gets capability for downloading data using `fetch()`, executing a timer etc. The timer-based
functionalities do not exist inside core JavaScript but due to the intervention of runtime,
runtime provides these kinds of functions or these kinds of API’s that JavaScript has access
to, and then use it. It will be dependent on runtime, what kind of resources, what kind of
architecture, what kind of functionalities it is actually providing you.

Why do we need a runtime?

A runtime is like a parent, when you were a small baby, you need parents to actually help
you for a lot of things. Similarly, runtime is required for JavaScript to help JavaScript in a lot
of processes.

Browsers are a runtime as well, you see chrome, you see edge and Firefox, all of these
browsers act as a runtime. Every browser has a different runtime, for example there can be
a case that some features are supported in one browser, and some features might not be
supported in one browser, because all these browsers are separate entities all together.
These are separate from JavaScript, there is no standard regulation that exists. This is why
one certain feature may work in chrome but may or may not work in certain way inside
Firefox.

For a very long period of time, the only runtime that existed for JavaScript were browsers,
different kinds of browsers. So, if a browser-based runtime is available then most of the
features are going to be revolving around browsers, their architecture might be different,
some of the API’s or functions might be different, but overall the features will remain as it
is.

2. Foundation of NodeJS –
In 2009 a person named Ryan Dahl released something called as NodeJS. NodeJS is an open
source, cross-platform, JavaScript runtime environment that lets us create servers, web
apps, command line tools and scripts. So, what Ryan Dahl did in 2009 was, they extracted
out JavaScript, the core JavaScript functionalities out of the browser in a runtime and they
setup a whole new runtime all together called as NodeJS. NodeJS enabled us to run
JavaScript directly inside out terminal. The browser-based JavaScript runtime cannot read
your file system, but JavaScript running inside NodeJS runtime can read it because it is
running inside the terminal. NodeJS runtime and browser-based runtime are different,
because inside your terminal you do not have HTML. So, there is no point of having DOM
manipulation functions such as:

• `document.getElementById()`
• `document.getElementsByClassName()`
NodeJS removes all of the irrelevant functions from NodeJS that are not required for you to
interact with the system, and provide some new set of functions and API’s that are going to
be more relevant, for example: A creation of file and deletion of file etc.

In a simple term NodeJS is a runtime inside which you can run JavaScript, it is similar to
browser but it does not provide browser-based features, instead it provides us a lot of
Operating System based features.

Key Points of NodeJS:

• NodeJS is an Open Source.


• NodeJS was created by Ryan Dahl in 2009.
• NodeJS brings raw (core) JavaScript features in to our terminal so that we can
actually interact with Operating System based features such as a creation of file and
updating a file etc.

3. Input and Output (I/O) –


I/O operations in your computer system are kind of expensive. Let us assume there is a process
running on and there is an input expected from the end user, so the end user can give the input
right away or they might take some time. So, I/O is kind of like one of the most expensive
operation that exists inside your computer.
I/O can be of two types:

1. Blocking I/O.

Blocking I/O is like there is a thread where the process is executing but then one process
waits for the user to give input. So, it will block the thread and wait until or unless input is
fulfilled.

2. Non-Blocking, I/O.

A Non-Blocking, I/O handles the situation differently. For example, Blocking I/O blocks the
thread until the operation is complete, but Non-Blocking I/O does not block the process and
executes next set of operation while performing the current process that is taking time
simultaneously.
4 What is NodeJS made of –
There 4 things that NodeJS is made of:

1. V8 Engine. V8 Engine is the JavaScript Engine that was developed by google for chrome.
2. JavaScript core functions.
3. Libuv library.
4. Bindings. It is a special program that helps NodeJS to interact with libuv library.

5 What is Libuv –
Libuv helps NodeJS to make it possible to be a Non-Blocking I/O while reading a file, no matter
what kind Operating System we are using, such as, if we talk about linux based file system, then
linux is a Blocking I/O and without libuv it would have been impossible for creating flawless
servers, Blocking I/O is something, which we do not want in NodeJS. So, what libuv library does
is, it makes the NodeJS compatible with all of the Operating System’s to work as a Non-Blocking
I/O.

You might also like