Node.js Server-Side JavaScript – What is Node Used For?

Ihechikara Vincent Abba

The release of Node.js in 2009 by Ryan Dahl increased the scope of what developers could do with JavaScript. Prior to that, you could only use JavaScript on the client side (the browser) or frontend of web applications.
With Node.js, developers can create server side applications, command line tools, and more.
This article is not a crash course on how to use Node.js (you’ll find resources for that in the last section of this article). Rather, it’s an introduction to what Node.js is, its features, and what it is used for.
What is Node.js?
Node.js is an open source JavaScript runtime environment that lets developers run JavaScript code on the server.
If that’s too complex for you to understand then you should think of it this way: Node.js is JavaScript that runs outside the browser — on the server.
Note that Node.js is not a programming language — it’s a tool.
What Is So Special About Node.js?
In this section, we’ll discuss some of the features that make Node.js cool to use.
The aim is not to compare Node.js to other backend technologies, but to help you understand some of its functionalities.
Single Threaded and Asynchronous
Node.js is fast at executing tasks (receiving requests and sending back responses) because of its single threaded and asynchronous nature.
Let’s explain some of the terms above.
By single threaded, this means that Node.js has a single source for handling requests. Multiple threaded backend technologies allocate a new thread for every new request.
You can think of a thread as someone who renders a service to multiple people. A very popular real life example would be a restaurant. We’ll explain this example further along with the asynchronous part of Node.js.
Node.js is asynchronous because it can handle multiple requests simultaneously. Let’s get back to the restaurant example.
A customer gets to a restaurant and sits down waiting for a server. The server gets to the customer’s table and takes their order. The order is then taken to the kitchen.
But the server doesn’t wait for the order to be ready before proceeding to the next customer. They’ll return with what the customer ordered for when its ready – in the meantime, the server proceeds to the next customer and repeats the same process.
The example above is similar to how Node.js works under the hood. It is able to process multiple requests using a single thread asynchronously (without waiting for one request’s completion before moving to the next).
So when the response for a request is ready, it is sent back to the client.
Introduction to Node.js
Getting started guide to Node.js, the server-side JavaScript runtime environment. Node.js is built on top of the Google Chrome V8 JavaScript engine, and it's mainly used to create web servers — but it's not limited to just that.
Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!
Node.js runs 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 runs in a single process, without creating a new thread for every request. 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 behavior the exception rather than the norm.
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.
Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.
In Node.js the new ECMAScript standards can be used without problems, as you don't have to wait for all your users to update their browsers — you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags.
An Example Node.js Application
The most common example Hello World of Node.js is a web server:
To run this snippet, save it as a server.js file and run node server.js in your terminal.
This code first includes the Node.js http module.
Node.js has a fantastic standard library, including first-class support for networking.
The createServer() method of http creates a new HTTP server and returns it.
The server is set to listen on the specified port and host name. When the server is ready, the callback function is called, in this case informing us that the server is running.
Whenever a new request is received, the request event is called, providing two objects: a request (an http.IncomingMessage object) and a response (an http.ServerResponse object).
Those 2 objects are essential to handle the HTTP call.
The first provides the request details. In this simple example, this is not used, but you could access the request headers and request data.
The second is used to return data to the caller.
In this case with:
we set the statusCode property to 200, to indicate a successful response.
What Is Node.js? Here’s How to Use Server-side JavaScript
With Node.js, you can add server-side functionalities to your applications using JavaScript (JS).
Before the introduction of Node.js in 2009, JavaScript was recognized as a frontend programming language, which meant that it was only used to manage aspects of a web application visible to the user.
Node.js is a game-changer. It allows developers to use JavaScript as a server-side language, effectively transforming JavaScript from frontend to full-stack.
What Is Node.js?
It’s important to understand that Node.js isn’t a programming language, but a run time environment of a programming language. Node.js is a server-side, packaged software that contains predefined processes to accomplish specific tasks.
As a server-side runtime, every Node.js process is executed on a server; essentially working on the backend aspect of an application to manage data. For instance, if you wanted to store some data in a file or a database, you’d need to employ the use of a server-side language or application.
Node.js is labeled as a JavaScript run-time environment because it uses JavaScript to conduct backend processes.
What Makes Node.js Special?
If you’re familiar with JavaScript you should know that it’s a client-side language, so it makes it possible for you to click a button and submit some information contained in a form. However, that’s as far as it goes; for that information to be stored in a file or a database, some other language would generally have to take over.
Node.js is so special because it gives developers the tools needed to connect to a file or database and store the data that was initially submitted from that form.
Before Node.js, a developer would need to know JavaScript along with other backend programming languages—such as Java or Python—to be called a full-stack developer. Today a full-stack developer can choose to learn only JavaScript and still be able to develop complete websites and applications.
How Does Node.js Work?
Node.js is built on the V8 JavaScript engine, which is used to compile and execute JavaScript source code. So when you execute a JS script using Node.js, that code is initially passed to the V8 JavaScript engine. The V8 JavaScript engine then compiles the script and passes the result of the compilation back to Node.js where it can be used in the application.
Why Use Node.js?
Node.js is a pretty popular backend technology used by big companies likes Netflix and Uber. There’s no doubt that Node.js developers are in demand. So why is this technology so popular?
Node.js employs a non-blocking I/O module, where I/O stands for input and output. This critical feature is one of the reasons for the technology’s popularity. Node.js being non-blocking means that while an I/O operation is being executed, access is still granted to other aspects of the application currently carrying out this I/O operation.
For context, consider the example of using a database with a web application. If a user wanted to retrieve extensive data from this database (a process that’s going to take some time) every other feature on this application (like clicking a random button) would be disabled until the I/O operation is completed if Node.js wasn’t using a non-blocking I/O module.
Creating a Node.js Script
A fundamental feature of Node.js is its node module system. This is a collection of different Node.js application programming interfaces that can be used to accomplish any task, from printing data to a console to storing data in a file.
One of the most popular Node.js modules is the file system module. It allows the developer to create and communicate with files on any given machine.
Using the File System Module Example
To use the file system module in your Node.js projects, you’ll first need to import this module. In Node.js, the file system module is represented by the acronym fs. So by simply passing fs to the required function (as shown in the code above), you now have access to the file system module.
The file system module is passed to the variable called fs, which could be whatever name you think is appropriate. That name was chosen because it accurately represents what will be stored in the fs variable.
The file system module has an extensive list of functions; the one used in the code above is called writeFile. The writeFile function takes three arguments: a filename, the data that is to be stored in the file, and a callback function.
The callback function takes an error argument that’s only available if a problem arises when trying to execute the writeFile function.
What Is Node.js Server-Side JavaScript?

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.