Introduction to Node.js

Neelakshi Lahiri
Last Updated: May 13, 2022

Introduction

If you’re already into web development, I’m sure you have heard the name node.js, but do you know what it is?


Don’t worry, because that’s what this article is about!

To begin with, the official node.js documentation defines it as,

“Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

Apart from the formal definition, some crucial points about node.js are:

  • It is an open-source server environment
  • Node.js applications are written in JavaScript and run on various platforms like Windows, Linux, Unix, Mac OS X.
  • It uses JavaScript on the server.
  • It is neither a framework nor a programming language
  • We use it to develop server-side and networking applications. 
     

Now that we know what node.js is, let us learn about its different features and applications. 

Why do we use it?

Whenever anything new is invented, it must be because there was a necessity for it. Similarly, whenever we’re learning something, either the need arises or we’re curious about why we’re learning it. 

In this context, why do we use node.js?

To understand this, let us consider the example of opening a file on the webserver and returning its content to the client. 

If this process is carried out using PHP or ASP, the steps involved are:

  1. The task is sent to the computer's file system.
  2. Waits while the file system opens and reads the file.
  3. The contents are returned to the client.
  4. Ready for the next request.
     

If this same process is carried out using node.js, then the steps will be:

  1. The task is sent to the computer's file system.
  2. Ready for the next request.
  3. When the file system has opened and read the file, the server returns the content to the client.
     

Thus, it is evident that no time is spent waiting in node.js. This is called asynchronous programming, and this is the reason we use node.js.

Features and Concepts

In the previous section, we already read about an important property of node.js because of which we use it. 

There are a few other such features. Let’s see what they are:

  • Easy to use - It’s easy to get started and can be used for prototyping and agile development.
  • Uses JavaScript - It uses JavaScript everywhere, making it easier for a JavaScript programmer to build backend services using Node.js.
  • Source code is cleaner and consistent.
  • It provides an extensive ecosystem for open source libraries.
  • Very Fast 
  • Single-threaded but Highly Scalable − Node.js uses a single-threaded program where the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
  • No Buffering − Buffering means waiting, and as we already know, there is no waiting before another request is handled in node.js. 
  • License − Node.js is released under the MIT license
     

Apart from the important features, some concepts of node.js can be seen at a glance from the picture below.

Applications Node.js

After knowing the basic facts about node.js, our next step is to know where it is used.

From a broader perspective, node.js can perform the following tasks:

  • Generate dynamic page content.
  • Create, open, read, write, delete, and close files on the server.
  • Collect form data
  • Add, delete, modify data in your database.
     

To be more specific, node.js is used in the following:

  • I/O bound Applications
  • Data Streaming Applications
  • Data-Intensive Real-time Applications (DIRT)
  • JSON APIs based Applications
  • Single Page Applications
  • Real-Time Chats
  • Complex Single-Page applications
  • Real-time collaboration tools
     

Some companies that use node.js are eBay, General Electric, GoDaddy, Microsoft, PayPal, Uber, and Yahoo!

Along with knowing where we use Node.js, we must also remember that it must not be used for CPU intensive applications.

Advantages of Node.js

Before we wrap up our discussion on node.js, let’s see the advantages of using it.

  1. Easy Scalability: Scaling the application in both horizontal and vertical directions is easy. Extra resources can also be added during the scalability of the application.
  2. Real-time web apps: While building chat apps or gaming apps, Node.js is much more preferable because of faster synchronization. 
  3. Fast Suite: Event loop in Node.js handles all asynchronous operations so all the operations like reading or writing in the database, network connection, or file system can be done quickly.
  4. Easy to learn and code: Node.js uses JavaScript, making it easier to learn and code. 
  5. Caching: Caching a single module saves the time needed to re-execute the code whenever there is any request.
  6. Data Streaming: In Node.js, HTTP requests and responses are considered as two separate events. They are data streams, so when a file is processed at the time of loading, it will reduce the overall time and make it faster. It also allows streaming audio and video files at lightning speed.
  7. Hosting: PaaS (Platform as a Service) and Heroku are easy to use hosting platforms for NodeJS application deployment.
  8. Corporate Support: Well-known companies like Walmart, Paypal, Microsoft, Yahoo use Node.js for building their applications. NodeJS uses JavaScript, frontend and backend Teams are combined into a single unit.

Frequently Asked Questions

  1. What is node JS?
    The official node.js documentation defines node.js as 
    “Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”
     
  2. Is Node JS frontend or backend?
    Node.js can be used in both the frontend and backend of applications and websites, thereby making the work of developers easier.
     
  3. Is Node JS a programming language?
    No, node.js is not a programming language, but it allows developers to use JavaScript, a programming language for creating web applications. 
     
  4. Name some companies that use Node.js.
    Some companies that use node.js are eBay, PayPal, Yahoo, Microsoft and Uber.
     
  5. List some advantages of using Node.js.
    Some advantages of Node.js are:
  • Easy Scalability
  • Real-time web apps 
  • Fast Suite
  • Easy to learn and code
  • Caching
  • Data Streaming
  • Corporate Support
     

Key Takeaways

In this article, we got a basic introduction to node.js. This includes the purpose of using it, its features, applications and advantages. 

This doesn’t seem enough, though.

Of course not!

Whether it is frontend or backend or even both with node.js, Web development is all about learning by doing. So next, we should learn how to set up a Node Server on Windows

Apart from that, you can also check out this course on Full Stack Development, which includes tutorials on Node.js.

Happy learning!

Was this article helpful ?
2 upvotes

Comments

No comments yet

Be the first to share what you think