🟒 Node.js – A Complete Backend Engine

What, Why, How, When explained clearly for learners

πŸ” What is Node.js?

Node.js is an open-source, cross-platform runtime that allows you to run JavaScript **outside the browser**, usually on the **server-side**. It uses the **V8 engine** (from Chrome) to execute JS code very fast.

It's not a programming language or framework β€” it’s a runtime that lets JavaScript work as a **backend language**.

❓ Why Use Node.js?

βš™οΈ How Does Node.js Work?

Node.js uses the V8 engine to run JavaScript, and a powerful internal system called the event loop to handle tasks asynchronously.

Instead of creating multiple threads (like Java), it uses a **single-threaded model** with **non-blocking I/O**. This makes it lightweight and highly efficient.

Simple Code Example:

// hello.js console.log("Hello from Node.js!");

Run it in terminal using:

node hello.js

πŸ“¦ What is NPM?

NPM (Node Package Manager) comes with Node.js. It helps you install and manage **third-party libraries** (called packages).

Example:

npm install express

This installs the popular web framework Express.js.

πŸ“ When and Where to Use Node.js?

πŸ“š Popular Modules in Node.js

πŸš€ First API Example (Without Express)

// api.js const http = require('http'); const server = http.createServer((req, res) => { res.end('Hello from backend!'); }); server.listen(3000);

Run it with node api.js and open http://localhost:3000 in your browser.

βœ… Summary