Node.js — Introduction

Dr. Ahmad Moussa
3 min readSep 18, 2021

--

What is Node.js? Why is it necessary? How does it work? Where to use it and what are its limits ?

What is Node.js ?

Node.js is a different version of Javascript. It is basically built on Javascript and that’s why it is called a Javascript Runtime.

Javascript is a language that runs in the browser and allows us to interact with the page after it is loaded. It’s needed very much in modern web development, and that is one of the most important advantages of Node.js.

Why Node.js ?

Via your browser, you can interact with the html page, the DOM (i.e., the Document Object Model). This interaction is limited, so there are some missing features that you can not do when you are in the browser.

For example, for security reasons, you can not work with your local file system; the feature is not supported by the browser. With Node.js, we can leverage the file system module (i.e., fs) to manipulate files (i.e., read & write files) into your system.

Node.js comes with some new added features. It allows us to run Javascript code not only on the server, but also on any machine, like a normal programming language. This means that we can use Node.js to run Javascript outside the browser.

Thereby, with Node.js we can do tasks that we can’t do in the browser, and that we don’t want to do from the browser. These tasks can be for performance and/or security reasons.

For example, the connection and the interaction with the database can be more performant to do it on the server-side. Also, the authentication of users can be more secured to be handled in a place the user can’t access (i.e., on the server-side).

So with Node.js we can do a lot of utility stuff which will never be exposed to the public.

How is Node.js working ?

Technically, Node.js uses the V8 Javascript engine built by Google. This V8 engine is an interpreter which takes the Node.js Javascript code and compiles it to a machine code, like what is done by a browser.

Node.js adds new useful features & functionalities to the V8 codebase, for example working with your local file system.

Where is Node.js used ?

Generally, Node.js is used in the context of web development, especially in server-side code (i.e., back-end). It is used to create and run a server, and also to listen to the incoming requests where you can define your own routing process. It also gives the capacity to interact with the database in a secure way.

What node.js CANNOT do ?

However, there are some missing features that you can do on the browser but not supported by Node.js. For example, you can not interact with the DOM using Node.js on the server-side.

Time to practice…

I made a very clarified tutorial that takes your hand to create a very basic and simple Node.js REST API. It is available here:

--

--