What is Node.js?

Node.js is a powerful, open-source runtime environment that allows you to run JavaScript code outside of a web browser. It uses Google’s V8 JavaScript engine to execute code on the server side.

Illustration of What is Node.js
Illustration of What is Node.js

💡 Core Idea

Node.js lets developers build fast and scalable backend applications using JavaScript, a language traditionally limited to browsers.

Unlike traditional JavaScript which runs in browsers to manipulate web pages, Node.js enables JavaScript to interact with the file system, network, databases, and more.

Node.js vs Browser JavaScript
FeatureNode.jsBrowser JavaScript
Execution EnvironmentServer (outside browser)Web Browser
Access to OSYes (file system, network, processes)No (sandboxed)
Use CaseBackend apps, servers, toolsWeb page interactivity
ModulesBuilt-in modules (fs, http, etc.)Limited to browser APIs

Node.js uses an event-driven, non-blocking I/O model that makes it efficient and suitable for data-intensive real-time applications.

💡 Event-driven & Non-blocking

Node.js can handle many operations simultaneously without waiting for each to finish, improving performance for web servers and apps.

📌 Deep Dive: Simple HTTP Server in Node.js

JAVASCRIPT
const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello from Node.js!');
});
server.listen(3000);
console.log('Server running at http://localhost:3000/');
Output
Server running message in console; server responds with "Hello from Node.js!" on port 3000

Node.js comes with a rich set of built-in modules such as http, fs (file system), path, and more, which help in building server-side applications efficiently.

💡 Why Use Node.js?

  • Write backend code in JavaScript
  • Build fast and scalable network applications
  • Large ecosystem via npm (Node Package Manager)
  • Great for real-time apps like chat and streaming

⚠️ Not a JavaScript Framework

Node.js is a runtime environment, not a framework like React or Angular. It provides the platform to run JavaScript on servers.