What is Node.js and its features ?

How to Upgrade (or Downgrade) Node.js Using npm | Surreal CMS

What if we start with these questions that may always come to your mind:

1- Why is Node.js so much accepted by professional web developers?
2-What is the source of this Node.js speed? What do I benefit from?
3- Is Node.js Ripe? Do I also have to start learning and working on it?
Rest assured dear reader, these questions we will try to answer in this new lesson, which will enable you to know everything that interests you about this new platform, which caused a sensation among the web immediately after its release in 2009.


History of JavaScript

Some believe that Javascript is just a tool to add some beautiful effects to your site, but this is not true, because Javascript is a programming language just like what are the languages ​​of Java, PHP and C and others, and perhaps this wrong evaluation in which some people are located is justified historically since this language has passed It has several stages since its inception in 1995, and we may be able to summarize it in three main stages:


1. The 1990s: the Netscape and Internet Explorer 5

At this time we were talking about DHTML or Dynamic HTML and as you understand from the name this technique was able to add some aesthetic effects on the page and give it a new vitality (for example adding text or an image to the page when pressing a specific button) the opposite of what was the situation before this time The webpages were static and not vital.


2. The beginning of the third millennium

This period is very important and witnessed the beginning of the emergence of JavaScript applications in conjunction with the emergence of famous libraries such as Geekware and Mootools and of course the emergence of Ajax technology formed a huge boost for this language as it became an integral part of any website on the Internet.


3. Beginning in 2010

Here Javascript has made a huge and significant leap, especially after Google developed the fast V8 engine, which Ryan Dal built on the Node.js platform that gave Javascript another dimension where we can use Javascript outside browsers and deal with servers directly, thus developing fast and effective applications using only one language which is Javascript.

This period also witnessed the emergence of large numbers of Javascript libraries whose name ends with the letters js such as Angular, Backbone and Ember, which enables us to make single page applications in easier and more effective ways.


Javascript interacts with the server?

Yes dear reader, just as it is in the well-known languages ​​that deal with servers and databases such as PHP, Ruby, Java EE and others, so that you can send a request to the server and Node.js (using the built-in Http unit inside) will take over the task of sending the page that I requested it after contacting the database if necessary and this means that Node.js came to compete with the languages ​​we mentioned, and it has the ability to do so due to its many advantages.


Why is Node.js fast?

The high speed of Node.js is mainly due to two factors: the advanced Chrome V8 engine and the input / output input and output mechanism I / O, which is called in English non-blocking versus the blocking mechanism of other languages, mainly PHP.


JavaScript V8 Engine

Google Chrome V8 Engine


Nodejs uses the V8 JavaScript engine developed by Google Chrome programmers and made a fuss about it after its debut in 2008. It is characterized by great power and speed that enables it to implement JavaScript codes faster and lighter thanks to its adoption of advanced compilation technology called JIT Compilation ( Or Just In Time Compilation) that converts the program into codes that the machine understands during the execution of the program and not before the start of execution, unlike before the emergence of the V8 when most of the engines adopted the traditional mechanism of Interpretation.


Non-Blocking Mechanism

As everyone knows, Javascript is a programming language that is based on Events. That is why Nodejs has developed a non-blocking concept platform.

We can now translate the Non Blocking mechanism without obstructions while we translate the Blocking mechanism with the blocking mechanism.

To understand why this translation is, we'll see two examples illustrating the difference between the two mechanisms:


Obstructive Mechanism Vs Obstructed Mechanism

In the PHP language, for example, which adopts the blocking model, when starting the process of uploading two files, the program must wait for the end of uploading the first file in order to start uploading the second file. .

Whereas in Nodejs the matter is completely different, the latter depends on the non blocking mechanism where the program can start the process of raising the two files at the same time and at the end of the upload process we resort to callback functions for each file to do what we want.



Blocking vs Non Blocking in nopdeJs
This is only one example, and there are many examples that apply to the example of uploading files upload, such as dealing with the database and the use of Web Services, Web Api that always takes valuable time from the program. Nodejs avoids us wasting time and allows us to do other things Waiting for time-consuming tasks to end.


ExpressJs web application framework

We mentioned that the JavaScript world abounds with many libraries and frameworks that help developers to create professional applications and put them on strong foundations instead of starting from scratch and wasting time building the project structuring.

Fortunately for the developers of Node.js as well, the latter takes advantage of a large number of frameworks that make the task of creating applications with it easier, perhaps the most important of which is Express.js framework for web applications. This Freework is not as large as Symphony in PHP nor Django in Python, but its utility remains great and can only help Node.js developers advance their projects more quickly and efficiently.



End of the article

It is true that working on Nodejs is more complicated compared to programming languages ​​that compete with it, such as PHP, but it remains a revolutionary and promising solution for applications that require special speed and real-time interaction between the user and the server.


References:



Source : Link