node.js

Node.js: An Introduction for Decision Makers

JavaScript and The Web

JavaScript is a popular web programming language that is most often associated with the client side or Front End. It is comprehensive, considering that JavaScript is the language that interacts with the web page’s elements directly through the HTML DOM (Document Object Model). Almost all web developers must use JavaScript to some extent, whether on the Front End or Back End, JavaScript is everywhere on web applications! JavaScript is responsible for binding events to DOM elements, it has responsibility for adding/editing/deleting DOM elements, and most importantly, it is what fires web service calls (often via AJAX) to the Back End. Simply put, a majority of web developers will have to write JavaScript at some point.

Node.js Structure

node.js

The following diagram shows a Node.js server lifecycle.

“Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript runtime.” Using the least amount of words, Node.js is software that allows JavaScript to run on the server. Before deciding whether or not Node.js is a good option for your next web application, it is important to understand how it works. Node.js can be installed on any platform! It can run on Windows, Linux or Mac. This can save a lot of headaches when configuring and coding the application. This may be seen as an advantage, since your application will not be tied to any particular server architecture.

Other platforms and applications normally have an Application Starting Point event, function or file, where code is run linearly with a well-defined beginning and end. Node.js is different:  events are defined and attached to a server port, where they wait to run code until an event is triggered. “Node.js runs single-threaded, non-blocking, and asynchronously.”

This makes Node.js very fast and memory efficient due to the way that the server handles a new request.

It does not create a new thread, instead it starts running asynchronously and is always ready to handle the next request. This consumes less memory and makes the server fast, but it is important to understand when this is useful and when it may not be the best approach for a given set of business needs. This approach does not work as well as other options when the  application needs to perform a big, long, complex calculation but becomes very powerful when it is required to perform several actions at the same time or handle a high traffic load (horizontal scaling).

It is important to note that the Sleep function will make the main single thread sleep, therefore putting everything to sleep! Apart from being fast and asynchronous, Node.js is also lightweight thanks to its modular approach. Node.js code can be seen as defined modules on ports. Common frameworks are heavy and contain all the references possible to use within that framework even if they aren’t used in a particular implementation. On the other hand, since Node.js defines modules, the references are only loaded when they are deliberately included (they need to be included with the ‘require’ keyword).

FrontEnd + BackEnd

Taking into consideration that Node.js is cross platform, asynchronous and lightweight, it’s often a good option for many API’s or other Back End projects where each operation requested is comparatively lightweight in scope but many are potentially needed in a small timeframe (horizontal scale). JavaScript has historically been limited to the Front End, are you telling me that it is now a legitimate Back End technology as well? In many cases, yes!

This is another great advantage, now both the Front End and Back End for an application can be done in the same language thanks to Node.js. For the Front End, JavaScript alone is not sufficient, the developer also needs HTML, CSS, and often frameworks such as Angular, React, etc. But this has always been the way for JavaScript in Front End. The same can be said for using JavaScript on the Back End, where familiarity with new modalities and different libraries and frameworks can round out a Back End JavaScript developer’s skillset. However, you can imagine the great potential efficiencies and savings unlocked by having the same pool of developers familiar with a language equally powerful on both the Front and Back Ends! This is the promise of Node.js.

Popularity & Community

After exploring some of Node.js’s characteristics, it shouldn’t be surprising to know that even big companies increasingly are choosing to use Node.js in production environments. Some examples: Netflix, LinkedIn, Walmart, Uber, PayPal and many more. Being popular and active in various production environments and companies makes Node.js a technology that has one of the most important advantages for any technology under evaluation, the community. Node.js has a very large and fast-growing community, thanks to its efficiency and its unique abilities. This helps because if an environment running Node.js presents an issue or needs diagnostics or maintenance, it is highly probable that someone else has already encountered the same issue, and the solution can be easily found and digested.

A big community for a given technology means that there is a lot of support and documentation on the web, which can drastically shorten the time-to-resolution.
A big community gives rise to another advantage, Node.js has a package manager (NPM) available to facilitate downloading and using third party libraries. There are countless extensions in these libraries that offer solutions to most problems that a developer might face, reducing the learning curve or development time of the project.

Conclusions

Node.js is an exciting option for many web applications when its high efficiency and lightweight, modular design are taken into consideration. It can handle high traffic loads and high concurrency with sometimes game-changing performance compared to many other platforms. Running a Back End project on Node.js is comparatively simple, and since the majority of developers are already skilled to some degree with JavaScript, synergies and efficiencies on your team could be very advantageous. Finally, Node.js has become so popular in the last few years that it now has a large community that have created thousands of solutions and extensions for tackling all sorts of common problems. If your next project will be highly concurrent, and your team has a lot of existing experience with JavaScript, considering Node.js makes a lot of sense.