Node.js Summary

Kimchhun Tan
4 min readJan 20, 2021
Source: Wikipedia

Prelude

JavaScript is a scripting language that is one of the three core languages used to develop websites. Whereas HTML and CSS give a website structure and style, JavaScript lets you add functionality and behaviours to your website, allowing your website’s visitors to interact with content in many imaginative ways. In simple word, JavaScript is a browser-dependent and used fir UI only.

The year 2005 proved to be a big one for JavaScript. When Jesse James Garrett introduced Ajax, a revolutionary suite of technologies that included JavaScript. Ajax vastly improved user experience by allowing web pages to feel more like native desktop apps. This really pushed JavaScript into the spotlight as a professional programming language.

JavaScript: Come on… I am still in the frontend and browser-dependent.

Due to the popularity of JavaScript, in 2009, the CommonJS project set out to define and promote JavaScript development outside the browser by using modules to package useful code and functionality. This paved the way for the language that ran the frontend of the internet was able to tackle the servers behind the scenes and browser-independent.

JavaScript: That is my boy…

Introduction of Node.js

In 2009, Node.js was introduced and initially written by Ryan Dahl in 2009. For your information, Node.js is not the first server-side JavaScript environment, the first pioneer is Netscape’s LiveWire Pro Web which is about thirteen years old when at the time of Node.js introduction.

What is Node.js?

Node.js is an open-source and cross-platform JavaScript runtime environment that runs on the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.

A Node.js app is run in a single process, without creating a new thread for every request, unlike most of the others do. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behaviour the exception rather than the norm.

Node.js’ Feature

Node.js is:

  • Event-driven — It refers to a paradigm in which the flow of program execution is determined by “events.” These events can be something the users are doing — clicking on a specific button, picking an option from the drop-down. However, in server-side, it includes request coming, a response from data fetching so on and so forth.
  • Non-blocking I/O — When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back. This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.
Source

Last but the most important thing in Node.js: NPM

Node.js has built-in support for package management using NPM, a tool that comes by default with every Node.js installation. These open a way to the accessibility of a ton of libraries built by the awesome community which will solve most of your generic problems. With Node Package manager, you can use all of those package based on your need in your apps to make your development faster and efficient.

Conclusion

Node.js not a silver bullet for server-side application. It comes with pros and cons.

Pros

  • If your application doesn’t have any CPU intensive computation, you can build it in Javascript top-to-bottom, even down to the database level if you use JSON storage Object DB like MongoDB. This eases development (including hiring) significantly.
  • Crawlers receive a fully-rendered HTML response, which is far more SEO-friendly than, say, a Single Page Application or a WebSockets app run on top of Node.js.

Cons

  • Any CPU intensive computation will block Node.js responsiveness, so a threaded platform is a better approach. Alternatively, you could try scaling out the computation [*].
  • Using Node.js with a relational database is still quite a pain (see below for more detail). Do yourself a favour and pick up any other environment like Rails, Django, or ASP.Net MVC if you’re trying to perform relational operations.

--

--