What is Node.js?

a short story

Sullivan Young
Stackademic

--

What is Node.js?

Origins

Now to truly grasp the origin story of Node.js, we need to take a step back and go to the beginning… 2008. Well, more specifically, let’s go back a step further and say the early 2000s. If you were anything like me, you barely used the internet during this time. Granted I was 6 or 7 years old, lived out in the country with dial-up internet, and barely used the computer beyond playing Freddi Fish. Either way, the internet, for lack of a better term, was rather boring and slow.

For many developers navigating this time, the process of building web applications was a juggling act. Switching between frontend languages like JavaScript to backend tools like PHP to create a full-stack application proved cumbersome. The constant context-switching led to many challenges accompanied by numerous frustrations and headaches. This is where Ryan Dahl comes in.

In 2009, Ryan Dahl started working on something revolutionary for the digital landscape. A soon-to-be mathematician studying for his PhD in New York, Dahl switched paradigms himself and moved into web development. Traveling from the US to South America to Europe, Dahl found himself delving deeper into lower-level technology and the web stack. He recognized the issue of multiple languages being required to write functional, speedy, and interactive full-stack applications and wanted to do something about it. I.e. Node.js

Now to say Node.js was the first server-side JavaScript technology would be a lie. Dahl has even stated that he was inspired by other developers trying to do something similar. Other technologies include CommonJS (formally ServerJS), Jaxer, Ringo.js, and Rhino to name a few. Furthermore, JavaScript wasn’t even the language Dahl tried out first when attempting to build this asynchronous I/O paradigm.

What is Asynchronous I/O?

To understand Node.js, you need to have a general concept of Asynchronous I/O (Async I/O). Async I/O is a programming model that allows input/output (I/O) operations to be performed non-sequentially. In traditional synchronous I/O operations, when a program requests to read from or write to a file, it typically waits until the operation is completed before proceeding to the next task. This waiting period can introduce inefficiencies, especially in scenarios where multiple I/O operations are performed concurrently.

In the context of Node.js, async I/O is a core principle that underpins its design. Similar to JavaScript in the browser, Node.js utilizes an event-driven, non-blocking I/O model, which allows it to efficiently handle large numbers of concurrent connections without getting bogged down by I/O operations. This design choice (essentially the foundation of Node.js) has contributed significantly to Node.js’s popularity and effectiveness in building highly scalable and performant web apps.

So where was an async I/O paradigm before Node.js? Well, there really wasn’t anything. Asynchronous I/O was not as prevalent or well-supported in many mainstream server-side programming environments. Traditional server-side technologies like PHP, Ruby, and Java Servlets, often relied on synchronous I/O models. Before Node.js, many of these environments struggled to address the scalability and performant challenges associated with handling large numbers of concurrent connections.

NPM

If you’ve used Node, chances are you’ve used NPM (maybe Yarn too, but we will touch on that later). So what is NPM? NPM stands for Node Package Manager and is, shocker here, a package manager for JavaScript and Node.js applications. It is used for managing software dependencies in projects. Shortly after Node.js’s inauguration in 2009, Issac Schlueter (who was working at Yahoo at the time), recognized the annoyance of importing various packages into their Node.js applications. Using some inspiration from Yinst, the package manager that Yahoo used internally for development, Schlueter created the first version of NPM which has grown ever since into what we know and use almost daily as JavaScript developers.

So chances are, you’ve also heard of or used Yarn. Anyways, it’s pretty simple. Yarn is just another package manager for JavaScript and Node.js. It was created by Meta (formerly Facebook) in collaboration with other tech companies as an alternative to NPM addressing some of the limitations and performance issues. We could write an entire article on the difference between Yarn and NPM, but luckily someone else already has! If you want to read more about these differences, check out this article.

We know its origin story, but what is Node.js?

Node.js is a program, or more precisely, a runtime environment you know and love to use today to execute JavaScript code OUTSIDE of a web browser. Originally, JavaScript code could only be executed client-side and there really only existed runtime environments in our browsers. When I say runtime environment, I mean a few things… Traditionally in the browser’s runtime environment, you have access to things like the DOM, Web APIs, Tasks and Microtasks queues, and the Event Loop. All of these work in conjunction with the JavaScript Engine to provide you with content that you view and interact with on your screen. You can think of Node.js as a wrapper around the JavaScript Engine that Dahl built where instead of having access to DOM and Web APIs, you have access to the file system, databases, and networks attached to the server.

Taking another step back… despite Node.js being a runtime environment FOR JavaScript, it’s actually written in C++. Why you may ask? Well, it’s because computers only understand Machine Code at the end of the day, or, 1s and 0s. That means we need a way to compile JavaScript code into Machine Code and the way it currently works with the browser you may be viewing this article with is a JavaScript Engine. In the context of Node.js, our attention will be directed towards just one JavaScript Engine known as V8 (as there are many engines out there). Developed by Google as the runtime engine for Chrome, V8 stands as an open-source powerhouse within the JavaScript ecosystem. So now… why V8? If I’m being honest, it’s mostly about timing. V8 and Chrome came out in 2008 and Dahl started working on Node.js in early 2009.

In summary, Node.js’s core is in C++ including its event loop and I/O operations. Node.js then wraps the V8 Engine, which is responsible for interpreting and executing JavaScript code (compiling it into machine code for your computer to read). You can almost think of Node.js as a bridge between JavaScript code and the underlying system resources, leveraging the V8 engine to execute JavaScript code efficiently in server-side applications.

Where is Node.js today?

Now it’s hard to gauge the popularity of Node.js because it is often grouped with JavaScript which is arguably one of if not the most popular programming languages out there. According to StackOverflow, 36% of professional developers are currently utilizing Node in some way, shape, or form in their jobs.

As for Dahl, he moved on from Node.js in the mid-2010s and went and built another runtime environment called Deno. He built this in response to some perceived limitations and security concerns of Node.js in 2018, with its first stable release in May 2020.

To touch on a common place of confusion, if you’ve heard of Node.js you’ve likely heard of something called Express. Express is a web application framework designed FOR Node.js to make building web applications and APIs easier. It provides routing with HTTP requests (GET, POST, PUT, DELETE), middleware, utility methods, error handling, and more.

Thanks For Reading

I just wanted to say thank you for reading my article! This took a good bit of research, but like all research things could be inaccurate. If something seems off please feel free to leave me a comment and I’ll look into it!

If you want to play around with Node.js you can download it here.

If you want the full background and origin story of Node, check out this amazing documentary by Honeypot.

Stackademic 🎓

Thank you for reading until the end. Before you go:

--

--