Check out other articles in this series:
This article series aims to provide readers with an overview of the architecture of Node.js, how Node.js works, and how it helps with organizing and writing better code.
This series is expected to have 4 parts, starting from basics to advanced topics. The content in each part is related, so make sure not to skip any of them.
In this first article, I will talk about Javascript and some basic concepts of Node.js.
Javascript is no longer unfamiliar to programmers. It is currently the dominant language on web browsers and widely used for front-end programming. Thanks to Javascript, developers can create websites that optimize user experiences.
Javascript was created by Brandan Eich, an employee of Netscape, in ten days in September 1995. It was originally named Mocha, then it was changed to Mona, and finally became the well-known Javascript.
In 1996, Javascript was officially named ECMAScript. ECMAScript 2 was released in 1998, and ECMAScript 3 was introduced in 1999. It has since evolved into the Javascript we have today, running on all browsers and devices, from mobile to desktop.
As of 2016, more than 92% of websites use Javascript, and it is currently the most popular language on GitHub for projects that utilize Javascript.
Javascript is widely used in web development, making websites dynamic and highly interactive. Therefore, Javascript code relies on browser support for execution, which is done by Javascript Engines.
A Javascript Engine is used to convert Javascript code into machine code. It acts as an interpreter and consists of the Memory Heap (which stores objects like variables and functions) and the Call Stack (which executes functions).
Most modern browsers use a Javascript Runtime to execute and convert Javascript code using Javascript Engines. Different browsers use different Javascript Engines.
For example, Chrome uses the V8 Engine, Mozilla Firefox uses the SpiderMonkey Engine, and Microsoft Edge (before using the Chromium engine) used the Chakra Engine.
Browsers also provide Web APIs that allow Javascript code to access certain objects like window
and document
, which are not part of the core Javascript language.
Because each browser uses a different engine, they may interpret Javascript code differently, resulting in different outcomes. This is why a website may work well in Chrome but behave abnormally in Internet Explorer.
Therefore, starting from 2016, Ecma International (the standardization organization for Javascript) introduced a naming convention for Javascript versions. ES5 refers to ECMAScript from 2009 to 2015, starting from 2015, versions are named ES6 - 2015, ES7 - 2016, and so on. Each year, the council approves and releases new ES versions. As of now (2021), ES12 is the latest version. Each version introduces improvements and new features, but their implementation depends on whether the browser developers support them or not.
Javascript was originally a front-end programming language and is widely known as one of the most popular programming languages in the world. Node.js was created with the aim of bringing Javascript to server-side development.
In 2009, Ryan Dahl used the fastest Javascript Engine - V8 from Chrome, and made it work without the need for a browser. This laid the foundation for the birth of Node.js. The V8 engine is written in C++ and allows direct execution on the operating system.
Node.js utilizes the V8 Engine to interpret Javascript code into machine code. Since Node.js is designed for server-side development, unlike browsers, some Web APIs such as window
and document
are not implemented.
It is also important to note that Node.js does not immediately support all features of Javascript (ECMAScript). It requires updates to support new ES features. This means that if you want to use new ES features, you have to wait for Node.js to update.
In summary, Node.js uses Javascript to implement its own code.
Check out the article on how to install Node.js: Installing Node.js and Running Your First Node.js Application.
No! Node.js is just a runtime environment for executing Javascript code. In fact, Node.js only provides a runtime environment for Javascript code through the V8 Engine from Chrome.
Let's review some conclusions about Node.js:
Node.js is composed of several interconnected components to create a complete environment. The following diagram describes the Node.js architecture:
In this diagram:
setTimeout
, File System like fs
, and Network Calls like http
.dns
module.crypto
module. The content in this article has provided an understanding of Javascript, Javascript Runtime, Javascript Engine, why some websites work well on one browser but poorly in another, the concept of Node.js, and an architectural overview of Node.js.
To understand how these components work, interact with each other, stay tuned for Part 2 of the Node.js Architecture series on 2COFFEE.DEV.
Hello, my name is Hoai - a developer who tells stories through writing ✍️ and creating products 🚀. With many years of programming experience, I have contributed to various products that bring value to users at my workplace as well as to myself. My hobbies include reading, writing, and researching... I created this blog with the mission of delivering quality articles to the readers of 2coffee.dev.Follow me through these channels LinkedIn, Facebook, Instagram, Telegram.
Comments (0)