Node.js Explained

Raz Gaon
The Startup
Published in
5 min readApr 29, 2020

What is Node.js?

A general misconception is that Node.js is a programming language. This article will explain the ins and outs of Node.js, helping you build a better foundation for potential future projects.

The short version

Node.js is a JavaScript runtime environment that enables developers to execute Javascript code outside the browser.

The long version

Prior to 2009, Javascript was almost exclusively used inside browsers. Each browser had a Javascript engine that executed the code. Developers had to write server-side applications with different programming languages such as Python, PHP, Java, etc. The issue during this period was that any developer who wanted to write Javascript code both on the client-side and on the server-side had to learn an additional programming language.

Disclaimer: Netscape (the company that created JS) developed a server-side Javascript environment called LiveWire Pro Web, but it didn’t gain traction and wasn’t widely used.

Then came Ryan Dahl…

Dahl created Node.js because of the limited ability of popular HTTP servers like Apache to handle concurrent connections. He envisioned a server that can handle a magnitude of concurrent connections in a non-blocking way.

Under the hood, Dahl used Chrome’s V8 Javascript engine to empower Node.js.

Why use Node.js?

For the sixth year in a row, JavaScript is the most commonly used programming language.

Stackoverflow annual developer survey

Node.js continues to be the most commonly used technology in this category.

Stackoverflow annual developer survey

Node.js represents a “JavaScript everywhere” paradigm, unifying web application development around a single programming language, rather than different languages for server- and client-side scripts.

A little bit of history

JavaScript is a programming language that was created at Netscape as a scripting tool to manipulate web pages inside their browser, Netscape Navigator.

Netscape

What is a web browser? It is a container that enables you to run numerous applications without downloading them to your device. Every mobile phone user has at least 20 applications on his device. In reality, a browser can run all of these applications without the user downloading a single one.

One key factor that led to the rise of Node.js was the timing. Just a few years earlier, JavaScript had started to be considered as a more serious language, thanks to the creation of more advanced web applications. Coupled with the realization that web browsers should serve the user the same experience as a native application, fueled the rise of Node.js.

As a result, JavaScript engines became considerably better as many browsers competed to offer users the best performance. Major browsers gradually offered better support for JavaScript and improved the execution speed of Javascript in the browser. The leading Javascript engine, V8, lead the improvement of the Javascript engines.

Node.js Ecosystem

Since the introduction of npm (Node Package Manager), over a million libraries were built by the community. Node.js has an extremely rich ecosystem, with the most third-party libraries out of all other ecosystems.

Node.js has libraries that can handle almost any task, ranging from Machine Learning to parsing Excel files. Once you get comfortable with npm and the ecosystem, you can find many jewels that will accelerate your development process.

Node.js And The Browser

Both the browser and Node.js use JavaScript as their programming language.

As a full-stack developer, using the same language for the front-end and the back-end is a huge relief and time-saver. No more syntax errors, different naming conventions, different libraries, etc.

It is difficult to fully, deeply learn a programming language, and by using the same language to perform all your work on the web — both on the client and on the server, Node.js enables you to maximize your knowledge.

A great combination, for example, is Nestjs and Angular. Nest’s architecture patters are mostly derived from the Angular project, thus developers who combine both frameworks use the same architecture both in the client and in the server.

So I mentioned that Node.js uses Chrome’s Javascript engine. What is the difference then between executing Javascript on Chrome and on Node.js?

In the browser, we have the window object available. In Node.js we have process . Why? In the browser, most of the time what you are doing is interacting with the DOM or other Web Platform APIs like Cookies. Those do not exist in Node.js, of course. In the browser, on the other hand, we do not have access to the host’s resources as we do in a Node execution environment (filesystem, memory, etc).

Another big difference is that in Node.js you control the environment. You mostly know which version of Node.js you will run the application on. Compared to the browser environment, where you don’t get the luxury to choose what browser your visitors will use, this is very convenient.

This means that you can write all the modern JavaScript versions that your Node.js version supports.

Summary

Node.js is an amazing tool for developers to use on the back-end. It enables developers to use the same programming language throughout the whole development process. Node.js has a very modern approach and is suitable for handling concurrency.

--

--

Raz Gaon
The Startup

Software Developer, Student at MIT, passionate about web development, writing, and boxing.