Episode 1 of 12

Introduction to Node.js

Learn what Node.js is, why it's so popular, and how it works under the hood with the V8 engine and event-driven architecture.

Welcome to the Node.js Tutorial for Beginners series! In this first episode, we'll explore what Node.js is, why it's become one of the most popular technologies in web development, and how it works under the hood.

What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript code outside the browser — on servers, desktops, and even IoT devices.

Before Node.js, JavaScript was confined to the browser. Server-side code had to be written in languages like PHP, Python, Ruby, or Java. Node.js changed everything by allowing developers to use one language (JavaScript) for both front-end and back-end development.

Why Use Node.js?

  • JavaScript everywhere — Use the same language for client and server, reducing context-switching
  • Non-blocking I/O — Handles thousands of concurrent connections efficiently
  • Massive ecosystem — NPM (Node Package Manager) has over 1.5 million packages
  • Fast execution — Built on V8, one of the fastest JavaScript engines
  • Great for real-time apps — Chat apps, live streaming, gaming servers

How Node.js Works

Traditional server-side languages use a multi-threaded model — each request gets its own thread. This works but is resource-intensive. Node.js uses a single-threaded, event-driven, non-blocking I/O model:

  • A single thread handles all requests
  • When a request involves I/O (reading files, database queries), Node.js delegates it and moves on
  • When the I/O completes, a callback fires to handle the result

This makes Node.js incredibly efficient for I/O-heavy applications like web servers, APIs, and real-time services.

Setting Up Node.js

To get started, download and install Node.js from nodejs.org. Choose the LTS (Long Term Support) version for stability. After installation, verify it works by opening your terminal:

node -v
npm -v

You should see version numbers for both Node.js and NPM. You're ready to start coding!

Your First Node.js Program

Create a file called app.js and add:

console.log('Hello from Node.js!');

const name = 'NoteArc';
console.log(`Welcome to ${name}`);

// Node.js can access the file system, network, and more
const os = require('os');
console.log('Platform:', os.platform());
console.log('CPU Cores:', os.cpus().length);

Run it with node app.js — congratulations, you've just run JavaScript outside the browser!