Browse Definitions :
Definition

Node.js (Node)

What is Node.js (Node)?

Node.js (Node) is an Open Source, cross-platform runtime environment for executing JavaScript code. Node is used extensively for server-side programming, making it possible for developers to use JavaScript for client-side and server-side code without needing to learn an additional language. Node is sometimes referred to as a programming language or software development framework, but neither is true; it is strictly a JavaScript runtime.

Node incorporates the V8 JavaScript engine, the same one used in Google Chrome and other browsers. It is written in C++ and can run on macOS, Linux, Windows and other systems. The engine parses and executes JavaScript code. It can operate independently of a browser environment, either embedded in a C++ application or implemented as a standalone program. The V8 engine compiles JavaScript internally, using just-in-time (JIT) processes to speed up execution.

The following code is an example of a simple JavaScript file (server_tst.js) written for the Node environment. The script starts by loading the Node.js Hypertext Transfer Protocol (HTTP) module. The module includes a variety of classes and methods for implementing an HTTP server.

Node.js example
Example of a simple JavaScript file written for the Node (Node.js) environment.

After Node.js is installed on a computer, the file can be run using a simple command: node server_tst.js. The JavaScript code instructs Node to carry out two basic operations:

  • Display a message in a browser on the local machine when connecting to http://localhost:2000. The message reads, "This is a test of Node.js on a local computer."
  • Return a message to the console when the command is run. The message states, "Node.js server running at http://127.0.0.1:2000/."

More details about the components in this script and the HTTP module in general can be found by referring to the HTTP topic in the official API reference documentation published by the Node.js organization.

How does Node.js work?

A Node application runs in a single process. Node does not create a new thread for every request, as is often the case with traditional server-side programs. In this way, a Node server can handle thousands of concurrent connections without having to contend with thread concurrency issues or the overhead multithreading brings.

Node.js is event-driven and runs asynchronously. Code written for the Node environment does not follow the traditional model of receive, process, send, wait and receive found in other systems. Instead, Node implements an event loop that processes incoming requests as they stack up in the event queue, handling small requests one after the other without waiting for responses.

This is a shift away from mainstream models that run larger, more complex operations and process several threads concurrently, with each thread waiting for its appropriate response before moving on.

The Node.js approach offers a major advantage over these models, according to its creator Ryan Dahl. Node does not block input/output (I/O) operations like more traditional approaches. This is in large part because Node functions do not perform I/O directly, which helps eliminate the potential for blocking. Blocking occurs only when using synchronous methods in the standard Node library, but that is the exception rather than the rule, making Node well suited for real-time applications with heavy concurrent workloads.

Node also ships with the npm command-line interface (CLI). The CLI is part of the npm package management system, which includes an extensive registry of JavaScript software and its meta information. The CLI lets users interact with npm packages in the registry directly from their consoles. The registry is reportedly the largest single language code repository in the world.

Like JavaScript, Node is considered relatively easy to learn. It is widely implemented and has a large, active user community behind it. In addition, because Node is asynchronous, event-driven and non-blocking, it can handle the type of real-time concurrency common in many of today's web applications and online services. Node is well suited to real-time applications such as chats, streaming services, internet of things (IoT) offerings or single-page applications.

Node is not suited to every type of workload, however. For example, because of its single-threaded nature, Node might not be able to effectively run a processor-intensive web application that requires heavy server-side computations. The computational load could end up blocking incoming requests and degrading overall performance.

On the other hand, if Node appears to meet your needs in all other respects and the computational load is not too excessive, you might be able to implement that load as background processes in another language. Node can also be used as part of a microservices architecture that breaks the application into smaller parts.

See also: Django vs. Node.js: Pick the right web development framework

This was last updated in November 2022

Continue Reading About Node.js (Node)

Networking
  • subnet (subnetwork)

    A subnet, or subnetwork, is a segmented piece of a larger network. More specifically, subnets are a logical partition of an IP ...

  • secure access service edge (SASE)

    Secure access service edge (SASE), pronounced sassy, is a cloud architecture model that bundles together network and cloud-native...

  • Transmission Control Protocol (TCP)

    Transmission Control Protocol (TCP) is a standard protocol on the internet that ensures the reliable transmission of data between...

Security
  • cyber attack

    A cyber attack is any malicious attempt to gain unauthorized access to a computer, computing system or computer network with the ...

  • digital signature

    A digital signature is a mathematical technique used to validate the authenticity and integrity of a digital document, message or...

  • What is security information and event management (SIEM)?

    Security information and event management (SIEM) is an approach to security management that combines security information ...

CIO
  • product development (new product development)

    Product development -- also called new product management -- is a series of steps that includes the conceptualization, design, ...

  • innovation culture

    Innovation culture is the work environment that leaders cultivate to nurture unorthodox thinking and its application.

  • technology addiction

    Technology addiction is an impulse control disorder that involves the obsessive use of mobile devices, the internet or video ...

HRSoftware
  • organizational network analysis (ONA)

    Organizational network analysis (ONA) is a quantitative method for modeling and analyzing how communications, information, ...

  • HireVue

    HireVue is an enterprise video interviewing technology provider of a platform that lets recruiters and hiring managers screen ...

  • Human Resource Certification Institute (HRCI)

    Human Resource Certification Institute (HRCI) is a U.S.-based credentialing organization offering certifications to HR ...

Customer Experience
  • contact center agent (call center agent)

    A contact center agent is a person who handles incoming or outgoing customer communications for an organization.

  • contact center management

    Contact center management is the process of overseeing contact center operations with the goal of providing an outstanding ...

  • digital marketing

    Digital marketing is the promotion and marketing of goods and services to consumers through digital channels and electronic ...

Close