Skip to main content

Command Palette

Search for a command to run...

What is Node.js? JavaScript on the Server Explained

Updated
4 min read

What are We Gonna Study?

Hey there folks! Hope you are doing great and enjoying your dev life.

Today we'll be talking about NodeJS, didn't you ever wondered why and how a language meant to be run on a browser runs on your code editor too?

For answering those questions you have to bear with me till the very end of this blog, with all your focus concentrated here.

Here is a list of topics we'll cover today:

  1. What Node.js is

  2. Why JavaScript was originally browser-only

  3. How Node.js made JavaScript run on servers

  4. V8 engine overview (high level only)

  5. Event-driven architecture idea

  6. Real-world use cases of Node.js


What NodeJS Is?

  • NodeJS is neither a framework or a library, it is a free, open source, cross - platform runtime environment for JavaScript.

  • It allows you to run JavaScript outside the browser ecosystem.

  • Ryan Dahl in 2009, created NodeJs.

What are the benifits of NodeJS?

  • Built on V8 Engine: NodeJS is built using the chrome V8 engine, that means they have the same level of high-performance.

  • Asynchronous & Non-Blocking: NodeJS uses an event-driven architecture, non-blocking I/O model. That's why it can do multiple task at a time without waiting for one to finish.

  • Single-Threaded Event Loop: Unlike traditional servers, who create a new thread for each request, NodeJS operates on a single main thread. It uses an "event loop" to manage thousands of concurrent connections efficiently with minimal overhead.

  • Universal Language: It allows developers to run JavaScript on both frontend and backend.


Why JavaScript was Browser Only?

  • Well initially, JavaScript was meant to be run on browser only, because the main motive of JavaScript was to make web pages interactive.

  • Also, there wasn't any infrastructure which can allow it to run out of the browser (Before NodeJS).

  • Also, in initial days, it wasn't fast too! but when google introduced the V8 engine of JavaScript, it hypothetically became capable of handling complex backend (Hypothetical because at that time, NodeJS didn't existed).


How NodeJS Made JavaScript Run on Servers?

  • Ryan embedded the V8 Engine into the open source C++ engine, along with LibUV and made NodeJS.

  • He ran it in his machine, instead of a browser, this allowed JavaScript to get compiled in machine code, which computer can understand.

  • Basically, it removed the need of language switching ilke PHP or Java or Python, etc.


V8 Engine (High Level Overview)

  • V8 engine is a javascript engine developed by google for chrome.

  • it is open-source, built using C++ and it's performance is high.

  • It translates JavaScript code directly into native machine code.

Key Aspects:

  • JIT Compilation: It offers JIT (just in time) compilation of code, It means it translates JavaScript to machine code at the runtime.

  • Garbage Collection: It manages memory automatically, cleans unused object for performance and stability.

  • Performance Optimization: It optimizes code execution, including "hidden classes" to speed up property access and inline caching.

  • Sandboxing: It provides a secure, isolated environment for executing JavaScript code.

V8 Engine be like:


Event-Driven Architecture Idea

  • Event-Driven Architecture (EDA) is a design pattern in which system components communicate by producing and reacting to events.

  • Examples: Change in state (meaningful) such as user clicking a button, successful payment,

  • Independent services (producers) announce that something happened and needing to know each other services (consumers) will act on that environment.

This is the high level idea of it.


Real World Use Cases of NodeJS

NodeJS is commenly used for:

  • Real-time applications (chat apps, live updates)

  • APIs and microservices

  • Streaming services (audio/video)

  • Single-page application backends

  • Collaboration tools

But not only that, NodeJS allows you to build a complete, high performance backend that is why you can use it literally everywhere!


Wrap Up!

Wasn't it amazing to know about NodeJS?
I personally enjoyed it a lot! Hope you enjoyed it too!

That was it for today's blog, I'll catch you up in the next blog, until then keep coding and enjoying your life 💝

NodeJS Backend

Part 3 of 15

This is an ongoing series that will most likely cover the following topics - Async Code in Node.js: Callbacks and Promises - Sessions vs JWT vs Cookies: Understanding Authentication Approaches - Storing Uploaded Files and Serving Them in Express - URL Parameters vs Query Strings in Express.js - How Node.js Handles Multiple Requests with a Single Thread - Setting Up Your First Node.js Application Step-by-Step - Creating Routes and Handling Requests with Express - JWT Authentication in Node.js Explained Simply - What is Node.js? JavaScript on the Server Explained - Handling File Uploads in Express with Multer - What is Middleware in Express and How It Works - Why Node.js is Perfect for Building Fast Web Applications - REST API Design Made Simple with Express.js - Blocking vs Non-Blocking Code in Node.js - The Node.js Event Loop Explained

Up next

The Node.js Event Loop Explained

What are We Gonna Study? Hey there folks! Hope you are doing great in your life, and enjoying the coding part of it too! Today, we'll be talking about some topics realtion to NodeJS Event Loop which a

More from this blog

L

Learning Tech

61 posts

A Blog with dozens of articles on different langauges as well as frameworks, This isn't just for you to learn, i crafted it thinking that this could be my future reference as well

It covers Networking, Web Development, Mobile Developement and very soon GenAI too!