Javascript continues to advance as years pass by, and the things developers can do with it now, could never be imagined earlier. If you’ve worked with this computer language, chances are that you might know something about Node.js. Despite having the experience of implementing Node.js in applications, there are things you might have missed or never discovered about this notorious JS component. We’ll start with the basics and maybe uncover some interesting facts along the way.

Fun Fact #1: Node.js came into existence 13 years after Netscape Livewire Pro Web, which was the first server-side JavaScript environment.  

Introduction to Node.js

Node.js is neither a language, nor an application development framework. It is simply a cross-platform open source environment that uses JavaScript on the server. It is compatible with almost every operating system (Windows, Mac, Linux, Unix etc.). Ryan Dahl is the inventor of this runtime environment, which was first officially released in 2009.

Node.js can also be described as a packaged compilation of Google’s V8 JavaScript engine, the libuv platform abstraction layer, and a core JavaScript library. The inspiration behind writing Node.js was applications like ‘Flickr’ and ‘Gmail’. The founder wanted to create real-time websites with push capability, in order to escape the ancient request-response paradigm.

Fun Fact #2: The Node.js APIs are generally just functions and have nothing to do with JavaScript.

What can Node.js Do?

In the past, JavaScript was limited to running within a browser; now it can run on computers like independent applications. Today, JavaScript is used for so much more than making websites interactive and a lot of credit goes to none other than Node.js. Apart from generating dynamic content, it allows developers to create, manipulate or discard database and files on the server; it also enables collection of form data.

Node.js modules are blocks of code that do not affect other code around them; also, they can be reused repeatedly. Developers can use these built-in modules instead of writing their own, without the need for installation.

Fun Fact #3: Node.js can run without V8; it needs a virtual machine which can be another one, such as ‘Chakra’.

How it Works?

Node.js utilizes a non-blocking event-driven Input/Output, which keeps applications efficient and lightweight, while running on globally distributed devices. Unlike traditional web services, it does not eat up RAM and actually runs single-threaded. The V8 engine uses a data structure (Call Stack) to keep track of functions. When the user requests a function, V8 places a reference on the call stack.

Node.js processes requests in a concurrent cycle, which is referred to as the ‘event loop’. Callbacks are predefined and let the server automatically access the event loop. When callbacks cease, Node exits the event loop. Node process can use different external libraries such as Zlib and C-ares. Therefore, if you encounter any bugs or glitches, they are most probably caused from these external libraries.

Fun Fact #4: You only get one Call stack per Node.js process, so remember to not keep it busy.

Limitations

Node.js is great for real-time applications having low I/O, for example chat or app monitoring dashboards. On the contrary, it is unfit for heavy server-side computation and processing. It is designed as a single threaded model, so CPU intensive operations will result in blockage of requests on an occupied event loop.  

Fun Fact #5: Hosting React applications on Node.js is a common practice, however it is not mandatory for using React.

Leave a Reply

Your email address will not be published. Required fields are marked *