What is Node.js?

5beberson
4 min readJul 28, 2021

This week I’ve been learning a little bit more about Node.js. I’ll cover what I learned and why this is used.

Description

Node.js or Node is an open source and cross-platform runtime environment for executing Javascript code outside of a browser.

Quite often we use Node to build backend services also called API’s(Application Programming Interface). These are the services that power our client applications like a web app running inside of a web browser or a mobile app running on a mobile device. These client apps are simply what the user sees and interact with. But these services need to talk to some services sitting on the server or in the cloud to store data, send emails or push notifications…

Why do we use Node?

Node is ideal for building highly-scalable, data intensive and real time backend services that power our client applications. So why do we use over other backend services such as Rails, Django… ?

  1. Node is easy to get started and can be used for prototyping and agile development.
  2. It can also be used for building super fast and highly scalable services. It’s used in production by large companies such as Paypal, Netflix, Uber, Walmart, and so on.

In fact, some studies found out that:

  • we can build twice as fast with fewer people,
  • in 33% fewer lines of codes,
  • using 40% fewer files.
  • They double the number of requests served per second
  • while decreasing the average response time by 35%

3. In Node applications, we use Javascript. So if you are a front end developer and know Javascript, you can reuse your Javascript skills and transition to a full stack developer. Simply put, you don’t have to learn a new programming language!

4. Also, because you can use Javascript both on the front end and the back end, the source code will be cleaner and more consistent. You will use the same naming conventions, the same tools and the same best practices.

5. Another reason of using Node is that it has the largest ecosystem of open source libraries available. So for pretty much any features or building blocks you want to add to your application, there is some free open source library out there that you can use.

Architecture of Node

Up to 2009, the only way to execute Javascript code was inside of a browser. Ryan Dahl, the creator of Node, came up with a brilliant idea. He thought it would be great to execute Javascript outside of a browser, so he took Google,s v8 engine (which is the fastest v8 engine out there) and embedded it inside a C++ program and called that program… Node.

So similar to a browser, Node is a runtime environment for Javascript code. It contains a Javascript engine that execute our Javascript code, but it also has certain objects that provide an environment for our Javascript code.

How Node works?

We saw earlier that Node is highly-scalable, and this is because of the asynchronous nature of Node. What this means is that a single thread is used to handle multiple requests.

When the database prepares the result, it puts a message in what is called: “an Event Queue”. Node is continuously monitoring this queue in the background. When it finds an event in this queue, it will take it out and process it.

This kind of architecture makes Node ideal for building applications that include a lot of disk or network access. We can serve more clients without the need to throw in more hardware.

In contrast, Node should NOT be used for CPU(Central Processing Unit)-intensive applications like a video encoding or an image manipulation service In these kind of applications, we have a lot of calculations that should be done by CPU and few operations that touch the file system or the network.

How to install Node?

To see if you already have Node on your machine, open your terminal or command prompt and type:

To install the latest version, head over to https://nodejs.org/en/

The recommended version on the left is the latest verified version, the one on the right is the experimental one and might not be stable.

Conclusion

I am in the process of experimenting Node by using a database with MongoDB. I will post about it in another blog.

--

--

5beberson

Made in France, built in USA. Living the American dream