Node.js Prerequisites

Node.js Prerequisites

November 6, 2023

Note: This article was translated from Chinese to English by Claude AI (Anthropic).

Node.js is a JavaScript Runtime Environment

Node.js® is an open-source, cross-platform JavaScript runtime environment.

Source: Node.js

Node.js is not a language but a platform, serving as a JavaScript runtime environment/host environment.

Any discussion of Node.js inevitably involves the Chrome V8 engine. In 2009, Google began developing the Chrome browser, now the most widely used browser, and the Chrome V8 engine developed under Lars Bak’s leadership was born, launching a performance revolution for JavaScript. Node.js was built on the Chrome V8 engine. Later, Node.js creator Ryan Dahl also built Deno.

Today, JavaScript’s architectural hierarchy has largely stabilized, as shown:

JavaScript architecture diagram

Source: Juejin Books

  • The bottom layer is the scripting language specification (Spec), ECMAScript.
  • Above that is language implementation, with JavaScript, JScript, ActionScript, etc., all implementing ECMAScript.
  • At the engine level, besides Chrome V8 mentioned above, there are SpiderMonkey, QuickJS, JerryScript, and other common engines.
  • The top layer consists of runtime environments, with Node.js, Chromium, Deno, and CloudFlare Workers based on Chrome V8, while Firefox is based on SpiderMonkey.

Basic Architecture

Node.js architecture diagram Source: medium.com

Node.js runs on top of the operating system, with its lower layer consisting of the Chrome V8 engine and some C/C++ libraries like libUv, c-ares, llhttp/http-parser, open-ssl, zlib, etc. LibUV handles event loops, while c-ares, llhttp/http-parser, open-ssl, zlib, and other libraries provide DNS resolution, HTTP protocol, HTTPS, and file compression capabilities.

The middle layer consists of Node.js Bindings, Node.js Standard Library, and C/C++ AddOns. The Node.js Bindings layer exposes the C/C++ library interfaces to the JS environment, while the Node.js Standard Library contains Node.js’s core modules. As for C/C++ AddOns, they allow users to bridge their own C/C++ modules to Node.js.

Above is Node.js’s API layer, which is what we primarily use when developing Node.js applications. Node.js applications ultimately run on top of the API layer.

Use Cases

  • Server-side

    Node.js provides event-driven and non-blocking interfaces for writing programs under high concurrency conditions. JavaScript’s anonymous functions, closures, callbacks, and other features were designed for event-driven programming.

    Some of Node.js’s built-in modules like http, net, fs were designed for server-side use. Whether it’s HTTP, TCP, UDP, or RPC services, Node.js can handle them all.

  • Desktop Applications

    Electron.js, an open-source framework developed and maintained by the OpenJS Foundation, aims to create desktop applications using web technologies with the Chromium browser engine and Node.js runtime environment.

    Software like Visual Studio Code, 1Password, DingTalk are all developed using Electron.

  • PC Games

    Besides writing browser-based games using WebGL or packaging games through Electron, JavaScript can also create genuine desktop games through Node.js bindings to use OpenGL or even DirectX.

  • Machine Learning

    pipcook

While Node.js was originally conceived as a technology for building server-side applications, as a JavaScript runtime environment operating within the operating system, it has evolved into a platform spanning front-end and back-end development, traditional services and Serverless, tools, business applications, games, and more.