$\textbf{What is Node.JS?}$
$\text{Written by:} $
$\text{Dev Singh, Class of 2022}$
$\text{Last Revised: March 2020}$
As supplied by the Node.JS official documentation, Node.JS is: “…a platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications.
Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices”. But what does this mean?
Code generally runs in two areas; server-side and client-side (hazard a guess as to what those mean). Node.JS runs on the server-side, whereas traditional JS runs on the client-side. This model makes Node.JS excellent for working on the backend (APIs, smart home, etc). Node.js can generate dynamic page content, edit databases, collect form data, and so much more.
Some enterprising developers have also adapted Node.JS to work on the client-side to create things like desktop and mobile apps, although those are more akin to standard JS. It’s important to note that Node.JS and vanilla (non-modified) JS are very similar syntactically: the key difference between the two is where they are used.
Chrome is known for utilizing a super-fast runtime for running JavaScript in the browser known as V8. V8 was created by Google for their Chrome/Chromium set of browsers as a way to speed up the user experience. V8 is unique in that it compiles JavaScript directly to machine-readable bytecode instead of more traditional methods, such as interpreting bytecode (official Python) or compilation (C-based languages, Dart). The main thing you need to really know for our purposes is that V8 is fast and is the basis for Node.JS code interpretation.
Traditional languages are generally considered blocking languages; while one action is being done, nothing else can occur on that same thread. One statement waits for the other to complete. This model, as you can probably guess, is pretty slow. Node.JS utilizes a non-blocking model where Node.JS utilizes callbacks (which we will discuss) to start the execution of multiple statements at the same time to minimize the time taken to complete a task. This non-blocking model is what makes Node.JS “lightweight and efficient”.
Node is generally used for I/O bound applications, Data streaming applications (Web), web APIs, and other web purposes. You should not use Node.JS for CPU intensive tasks (such as cryptography), since Node is single threaded.