Node.js: Using JavaScript on Server-Side

One of the JavaScript technologies that made JavaScript get so trendy nowadays is Node.js. How? - you will ask. Maybe just because it makes creating high-performing, real-time web applications easy, or it performs well anywhere? Or maybe because It allows JavaScript to be used end to end, both on the server and on the client side? Reasons are many and at Simply we decided to speak out loud and try to answer all the basic questions about this unique JavaScript technology - Node.js.

So if you wonder what's the superpower of this technology, or maybe you don't know what Node.js actually is or you even know a little bit about it, it is now the time to bring all your knowledge into a full shape. In this post you will find out all the truth about Node -  the technology that made the full-stack JavaScript development into a reality.

What is Node.js?

Let's start with understanding what is Node.js in fact. Node.js is an application runtime environment that enables using JavaScript (that used to be a client-side programming language) for building server-side applications that have access to the operating system, file system, and everything else to be fully-functional. Among other server-side technologies, Node stands out with its speed and intensive data exchange․

Node.js is built on Chrome's V8 JavaScript engine and it uses an event-driven, non-blocking I/O model to be both lightweight and efficient for server side applications. Npm, its package ecosystem, is one of the largest open-source libraries collections in the world.

How Node.js works?

What makes this technology so powerful, lightweight and efficient, is its unique I/O model that excels in many scalable and real-time situations demanded from the servers.  Let's find out how this model works.

"Every I/O operation in Node.js is asynchronous..."

Node.js developers take charge of the Event Loop instead of using threads, which empowers them with the ability to write apps that scale to millions of concurrent connections. It takes advantage of the fact that servers spend most of their time waiting for I/O operations, like reading a file from a hard drive, accessing an external web service or waiting for a file to finish uploading, as these operations are much slower than in case of memory operations. Since every I/O operation in Node.js is asynchronous, the server can continue to process incoming requests while the I/O operation is taking place. And as JavaScript is extremely well suited to event-based programming because of its anonymous functions and closures, for JavaScript developers it is really easy to write code in this way. It's this event-based model that makes Node.js very fast, and helps to scale real-time applications very easily.

PopularitY

Thanks to Node.js, JavaScript has become a vital language not just for web development, but for Platform-as-a-Service (PaaS). In fact, according to the Stack Overflow 2018 Developer Survey of 51,600 programmers, Node.js is the most popular of all developer frameworks.

  Stack Overflow’s Annual Survey of 2018

Stack Overflow’s Annual Survey of 2018

As for the Web3Techs reports, the usage of Node.js in web applications development historically grew and at the moment it looks like this.

noderanking.png

And maybe this popularity is the reason that, according Github Annual Octoverse Report 2017, Node.js is the 8th most discussed technology on their website.

  GitHub Octoverse 2017

GitHub Octoverse 2017

According to Mark Hinkle, executive director of the Node.js Foundation, a branch of The Linux Foundation, "With more than 8 million Node.js instances online, three in four users are planning to increase their use of Node.js in the next 12 months."

Why? Because, "the application platform helped improve developer satisfaction and productivity, and benefited from cost savings and increased application performance." On the business side, Node.js is expanding its markets.

Hinkle continued: "It is moving beyond being simply an application platform, and beginning to be used for rapid experimentation with corporate data, application modernization and IoT solutions." In addition, "Node.js use is beginning to rise in the Ops/DevOps sector and mobile as well."

On top of that, he said, "the use of Node.js expands well beyond containers and cloud-native apps to touch development with databases, front-end framework/libraries, load balancing, message systems and more."

Usage

Besides using Node.js for backend and frontend separately, at the same time, this technology happened to have a lot of applications of desktop, mobile app development, also for security reasons, and to the surprise of some of you, even in IoT.

Node.js and Desktop Apps

nodejs_slack.png

JavaScript is recognized primarily for making web pages interactive within web browsers, but the Node.js library enabled running JavaScript code outside the browser and allowed the development of an end-to-end applications in JavaScript. This is that we already know, right?

We also know that the most popular use of Node.js is for web application development. As for the desktop applications, technically it is impossible to build one with this server-side JavaScript technology. Why is it impossible and how do developers overcome this problem? Node itself doesn’t support a GUI, a type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators, and there are projects that provide GUI creation capabilities. If you’re writing apps with a GUI, Node can’t do it on its own. This is where Electron and NW.js come in, which are the leading technologies that bridge the GUI gap. 

Famous desktop apps like WhatsApp and Messenger are written in Node.js with the help of node-webkit. While, one of the most famous team collaboration tool -  Slack desktop application was written also in Node but with the help of Electron.

NOde.js in IoT

nodejsinIoT.jpg

Now Node.js is being adopted in IoT use cases, as well. It is becoming really popular for many IoT companies and situations as it is easy to use and rarely breaks. Node.js is used in IoT projects for both the device and the server.

Why do hardware engineers use it? Simply, it is fast, has lots of plugins, is scalable and is good at I/O, meaning it allows to control IoT from one point, hold effective and secure communications, and more. There are a lot of engines that provide all APIs to JavaScript, allowing it to interact with a microcontroller. And day by day many IoT JavaScript libraries appear in the field proving that the usage of the technology is rapidly growing. Johnny-five.io, Zetta.js, Cylon.js, Nodered, Device.js are some of the JavaScript libraries famous among hardware engineers.

Hosting Services Supporting Node.js

node-js.png

To the happiness of many developers and IT professionals, Node.js is supported by the biggest and best hosting services in the industry like AWS, Heroku, Microsoft Azure, Joyent, etc. Below you can find just some of the most popular services that support Node.js.

AWS - Amazon Web Services

Amazon Web Services (AWS) allows you to deploy a high-availability Node.js web application using the AWS Elastic Beanstalk service. This is a container system that makes it extremely easy to push packaged applications to AWS as Platform as a Service (PaaS). You have full control over the server on which your Node.js application runs, and indeed you can also run multiple applications on the server without incurring any additional costs.

Heroku

Initially only supporting Ruby on Rails, Heroku has since added support for a wide range of languages and environments including Perl, Python, PHP, Java and of course Node.js. Owned by Salesforce.com, Heroku also offers seamless integration with a host of third-party services and supports deployment across multiple regions. It is very easy to get started with Heroku even for the beginners. This hosting service has great support documentation available for free and an extensive list of plugins and services that can be added instantly.

Microsoft Azure

Microsoft Azure is Microsoft’s cloud-based platform that lets developers rapidly build, deploy, and manage powerful websites and web apps. This is a reliable platform with great flexibility and high-availability across multiple regions. With support for both Windows and Linux machines, you are able to monitor all of your Node.js applications hosted on Azure in real-time, with automatic scalability supported. This means it is super-easy to scale your Node.js app up or down here, and enable autoscaling - meaning letting Azure to scale in accordance with the traffic.

You can find more examples of Node.js supporting hosting services in another Simply blog-post here.

companies that use Node

  Netflix uses Node.js for its server-side.

Netflix uses Node.js for its server-side.

Node.js helped many popular companies to build various fully-functional applications like Netflix, Walmart, Uber, Paypal, etc. Netflix, the world's leading Internet television network with over 117 million users, is one of those top companies that trusted his servers to Node.js. The technology helped to reduce its application startup time by 70%. Walmart, the world’s largest retailer, re-developed its mobile app to provide more advanced features on the client side.  The three core sides of Node.js that made it a good fit for Uber were asynchronous I/O requests handling, quick iterations and the active open source community. So, in another blog post we have put together 8 top companies that trusted Node and tried to understand the reasons that make the industry leaders like Netflix, Walmart, Uber, etc. choose this technology.

IN SHORT

Node is truly the technology to blame for JavaScripts popularity, but this is not pointless. It is fast, efficient, and secure.

 

Do you love coding in me? I’ll make you feel the same way!
— Node.js

Node.js is talked as much as it is loved among the professionals because maybe this love is mutual? Who knows! ;)

- Simply