What Is Node.js Server-Side JavaScript?


What Is Node.js Server-Side JavaScript?

Original Article


According to reports, JavaScript is being used on 97% of all websites. That's huge! But that's just on the web. JavaScript is everywhere these days, including desktop, mobile, IoT, embedded devices, servers, and even drones. You name it. It's everywhere. But today we'll talk about its use on the server-side and what exactly server-side JavaScript is.

What Is Server-Side JavaScript?

Server-Side JavaScript is the use of the JavaScript language on servers. You know, those computers that are always on (and maybe online) running stuff, doing all kinds of work. Nowadays many of them have software, web servers, command-line applications, and other services that are written in JavaScript. But how did JavaScript come from the browser to land on the server? That's what we will be discussing in the next section.

Brief Origin of The Language

You see, in the beginning of the web, it was all static. It's true that you might have a language on the server to generate HTML pages through some templates, but once the browser downloaded the code, there was no more interactivity. It was, for a lack of a more inspiring word, boring. In the old days, web pages were plain simple. You have your structured HTML content, some CSS, and maybe some images here and there. Done. Then a guy named Brendan Eich, who was working at Netscape at the time, was tasked to create a scripting language to add a bit of interactivity to their Netscape Navigator browser. The language would be created to compete with a similar scripting language called JScript of the same era, which came from Microsoft for its Internet Explorer browser. Interactivity meant being able to do basic validation on an input for a form and do something when a button is clicked. Eich created the first version of JavaScript in 10 days. Yeah, just 10 days.

Fast-forward a couple of years later, Google had its map service that was making really advanced use of the language, using XMLHTTPRequest to update their map in real-time while users were navigating around. That contributed to the popularity of the language because it showed what was possible in a browser at the time. The AJAX (Asynchronous JavaScript and XML) term was coined around that time and was becoming a popular technique to get new data on a web page without reloading it and this quickly became a common use of the technology.

Then in 2009, another guy named Ryan Dahl created Node.js, which we will discuss in the next section.

What is Node.js?

Node.js is a runtime environment to allow JavaScript to not only be run in the browser, but also on the server (or almost any environment, really). That also expanded the types of applications that could be built with the language since it wasn't tied to only the client-side anymore. After that, the popularity of the language exploded. Node is available on Windows, Linux, Mac, and many other platforms. Developers started using the power of the platform, which allowed them to access APIs such as the filesystem and to use powerful applications. Popular projects have been created to ease the development of software, web, desktop, mobile, and other types of applications. Thanks to Node, Chromium, and Electron we can now have sophisticated IDEs like Visual Studio Code, programming languages like TypeScript, powerful command-line applications like React Native, and Expo to create mobile apps with React. This is all possible because JavaScript is now available everywhere.

Server-Side JavaScript vs Client-Side JavaScript

So JavaScript can now be used not only on the client-side but also on the server. But what's the difference between the two? Well, remember the old days of the web I mentioned above? JavaScript as a language has evolved a lot throughout the years. It had to in order to support the demand and need for more powerful APIs and features to better support the growth of the web 2.0 era. JavaScript was being considered a serious language now and the arrival of HTML5 around 2011 was confirmation that you could create more than just web applications in a web browser. We had WebGL, Canvas, Audio, and more starting to become available in the major browsers allowing rich games to be experienced inside the browser. It was a literal game-changer (pun intended). JavaScript was no longer used to add interactivity to web pages, it was used to build full-blown web apps that behave like native desktop and mobile applications called Single Page Applications. SPA for short.

So, now that JavaScript is available in other environments like the server as well, nothing can prevent a developer familiar with JavaScript on the client-side to use it to create an API or a web server, as well to complement their web application. And so both client-side and server-side JavaScript aren't mutually exclusive. They can be used together. And that's what we'll touch upon in the next section.

Combining Server-Side & Client-Side JavaScript

A common use of both ways of using the language is to use it client-side to build and update UIs (user interfaces) and have server-side code serve data required for the client to work.

Client-Side JavaScript is also no longer exclusive to the browser. If you are building a desktop or a mobile app, they are also called client-side apps. That's because modern apps usually depend on external data to work. And so they fetch the data from a server, usually a JSON API, and process it in different ways.

For example, if you are building a social network mobile app with React Native, (a hybrid mobile app framework by Facebook) that allows people to chat, post, like, and comment together, then you will probably need an API to allow data retrieval, storage and other actions. Using Node.js for this is a really good idea because it's fast (thanks to its event-driven non-blocking runtime environment) and your clients will have a fast response and good experience. Node.js can not only support HTTP requests, but also WebSockets connection for bi-directional communications in real time between clients. Node.js has a bunch of primitives that can be combined together to build more complex systems. It comes with NPM, a package manager that allows developers to install packages from a very large collection to build almost anything!


As you can see, JavaScript on the server-side (or outside of the browser) has opened a wide range of applications for the language. And that's one of the reasons it is one of the most popular right now. Knowing JavaScript well will open new opportunities for jobs as well since more startups and companies are looking for new talent to build innovative and exciting products for them. There's no better time to be a JavaScript developer than now. Especially when companies like G2i make it even more accessible for developers around the world to work for great companies and enterprises. Today's developer just has to be good with JavaScript, Node.js, and React.