What and Why Node.js?

A historical context and a developer perspective

Leandro 🤖 👾 🚀
4 min readMar 11, 2021

A Brief Timeline

Ryan Dahl created Node.js in the year of 2009 to run JavaScript on the server-side. By the time the community did not embrace the idea, a new version of Ruby on Rails had just been released, and developers worldwide were eager to start coding.

In 2010, Ryan Dahl's luck started to change when Isaac Schluter created the Node Package Manager (NPM). The package manager allowed Node.js developers to share and maintain packages easily.

Figure 01: Photo by AltumCode on Unsplash

Another great ally for Node.js was MongoDB. Developed around the same time, MongoDB is a NoSQL database that uses JavaScript Object Notation (JSON) to store data as documents, which became very handy when social media applications started popularizing RESTful JSON APIs.

After some time maturing, a few packages released helped popularize Node.js: ExpressJS and Mongoose. Those packages made it so easy to develop server-side applications that the dev community could not ignore them any longer.

But Seriously, What is Node.js?

Until recently, the official website defined Node.js as:

A JavaScript runtime built on Chrome’s V8 JavaScript Engine. Node.js uses an event-driven, non blocking I/O model that makes it lightweight and efficient.

The Chrome V8 JavaScript Engine:

V8 is a Google open-source project written in C++ that compiles and executes JavaScript code. When JavaScript was first developed, each web browser had a different JavaScript engine such as SpiderMonkey for Mozzila use in Firefox, JavaScriptCore for Apple’s use in Safari, and the V8 for Google use in Chrome.

A JavaScript Runtime:

In fact, Node.js is not a programming language. Like Google Chrome, Node.js uses the V8 engine to provide and extend JavaScript functionalities, for example, reading and writing into the file system on your computer.

Event-Driven:

Most APIs in Node.js are asynchronous. They implement objects called “emitters”, which provides methods to emit signals to functions objects called “listeners”.

A good analogy is the well-known HTTP request. Every time a user clicks in a button an event listener receives a signal to execute some action. The counterpart in Node.js could be an operation to read and write from a file on your computer.

The combination of events and callbacks made it possible to handle asynchronous operations in Node.js applications. Nowadays, one can make use of “Promises” or “Async/Await” features provided by newer versions.

Non-Blocking I/O:

Node.js uses the callback pattern, which is popular for asynchronous tasks because they can propagate the result of some operation to be consumed later in the future without blocking the execution flow.

Figure 02: Two programs to explore synchronous and asynchronous operations.

In figure 02, one can see two programs that execute the same flow with the same function-defined doWork() using the callback pattern. On the left, the sync.js program executes line-by-line. However, the async.js program on the right uses the function setTimeout() inside the doWork(), which delays the output by around one second, resulting in the message “I am doing some work” to be displayed after the last line of code console.log(“Finish”).

Why Node.js?

Even though Node.js is fairly new, it has a huge active community. This can be observed by the number of third-party (npm packages) shared among developers with well-written elegant solutions like Express.js.

From a developer perspective, you may already use, changed or even updated a JavaScript code in the frontend of any application. Besides, writing code in JavaScript can be a faster way to start up your project or test a hypothesis.

Every programming language has its pros and cons. Of course, it will depend on your goals, abilities and preferences, however, like other major programming languages out there, JavaScript is here to stay, and by consequence, Node.js is likely to keep improving and gaining more space among developers.

--

--

Leandro 🤖 👾 🚀

A Tech adventurer aiming to explore and share the latest advancements in technology. Do you want to join my guild and level up with me?