What is Node.js? Javascript on the Server


Have you ever wondered what happened to PHP? I used to play with it back in 8th grade — making small websites, handling user inputs, and feeling pretty cool about it. But over time, PHP seemed to lose its charm. And now, it feels like everyone is talking about just one thing: Node.js.
You might have heard the usual explanation — “Node.js is a runtime environment for JavaScript.” That sounds a bit confusing, right? So let’s break down what Node.js really is, why it became so popular, and how it changed web development.
JavaScript in the 1990s: Just for Browsers
JavaScript was created in 1995 to make websites more interactive, but only inside the browser. Back then, web pages looked like this:
Frontend: HTML, CSS, JavaScript (runs in browser)
Backend: PHP or similar languages running on the server
JavaScript’s job was to make buttons clickable, validate forms, and do simple animations — all inside your browser. But every time you submitted a form or clicked something that needed data from the server, the entire page would reload.
Imagine clicking "Register," and your whole screen goes blank while waiting for the server to respond. That was slow and annoying.
Also, servers worked synchronously — they handled one request at a time. So if one request took a while, everyone else had to wait.For example: If five people clicked "Register" at the same time, the server would only handle one request at a time, making the other four wait in line until the first finished. This made the whole process slow and frustrating.
AJAX Changed the Game in 2005
Then came AJAX. It allowed web pages to send and receive data from servers in the background, without refreshing the whole page. Suddenly, web apps felt faster and smoother.
You could click a button and get new info without waiting for a full reload. Cool, right?
But here’s the catch: JavaScript itself is still single-threaded and synchronous. That means it could only do one thing at a time, like a one-lane road where only one car can move.
The browser provides Web APIs — extra threads/tools that handle things like timers, events, and HTTP requests in the background. AJAX is a way to make HTTP requests asynchronously using these Web APIs.
What’s a Thread, Anyway?
Let’s understand threads with a simple example.
Imagine a road with just one lane. Only one car can drive at a time. If a car breaks down, all the cars behind it have to stop. This is how single-threaded programs work — one task at a time, blocking others.
JavaScript is like that single-lane road. It had just one thread, so it could only handle one thing at a time.
Why Was This a Problem?
While browsers could use AJAX to do some things asynchronously by using their own built-in features, servers back then didn’t have that luxury. Backend languages like PHP worked synchronously — waiting for each task to finish before moving to the next.
Plus, developers had to use two different languages: JavaScript on the frontend, and PHP or others on the backend. Switching between languages was extra work and sometimes confusing.
Enter Node.js: One Language to Rule Them All
In 2009, Ryan Dahl had an idea:
“If JavaScript can handle async stuff in browsers, why not run it on servers too?”
That’s how Node.js started.
What Exactly Is Node.js?
Node.js is not a new language — it uses regular JavaScript. Instead, it’s like a new environment where you can run JavaScript outside the browser.
Think of it this way: JavaScript was designed to run only inside browsers — like cooking only in a kitchen. Outside the browser, it didn’t have the tools to work with files, networks, or servers.
Node.js brings that kitchen setup — the stove, sink, and utensils — to your computer’s command line. Now, you can “cook” (run JavaScript) anywhere, including on servers.
How Does Node.js Handle Asynchronous Tasks?
JavaScript’s engine (called V8) can only run synchronous code — one step at a time. So how does Node.js handle many requests without blocking (asynchronous tasks)?
It uses a library called libuv that takes care of things like similar to the AJAX feature from Browser:
Reading files without waiting
Managing many network connections at once
Running background tasks
This way, Node.js can handle lots of things at the same time, making web servers fast and efficient.
Setting up your First Node.js App Step by Step
Firstly, ensure node.js has been installed in your system . Kindly refer this article for download documentation How to Install Node.js and npm on Windows, macOS & Linux :
Create a
.js
file in your code editor (here index.js)Type
node -v
in the terminal . If node.js is installed it would display the version numberWe import ‘http’ from the inbuilt http module which node.js provides this .This helps to set up a server on your localhost
const http = require('http')
Now create a server using by using the function createServer ()
const server=http.createServer();
Define the port on which the server has to run
Now pass a listen function on the server which you have created .
The port number: This will be the port on which the server will listen.
The callback function: This function will be executed when the server starts listening on the specified port.
const http = require('http')
const server=http.createServer();
const port=3000
server.listen(port,()=>{
console.log(`Server is running on ${port}`)
})
Output:
Success!! :)
Subscribe to my newsletter
Read articles from K Raghav directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

K Raghav
K Raghav
I am a B.Tech Computer Science student in my second year, aspiring to become a software engineer with a strong interest in web development. Currently, I am exploring development while actively practicing Data Structures and Algorithms (DSA) to enhance my problem-solving skills and speed. I am passionate about contributing to open-source projects and aim to work for a product-based startup or an MNC in the future.