Learn Node.js Hello, Node.js! — Your First Server-Side Program

Hello, Node.js! — Your First Server-Side Program

⏱ 15 min read
Node.js is a JavaScript runtime built on Chrome's V8 engine. It lets you run JavaScript outside the browser — on servers, your laptop, or anywhere.

How Node.js Works:
Before Node.js (2009), JavaScript only ran inside browsers. Ryan Dahl changed that by embedding V8 into a standalone runtime.
Node.js uses an event-driven, non-blocking I/O model — it handles thousands of connections simultaneously without waiting for each one to finish.
This is why Node.js is extremely popular for web servers, REST APIs, and real-time apps.

JavaScript runs everywhere now:
Browser — handles clicks, animations, and the DOM
Node.js — handles files, networks, databases, and servers

How to Install and Run:
1. Download Node.js from nodejs.org (includes npm — the package manager)
2. Save your file as hello.js
3. Open a terminal and run: node hello.js

Breaking Down Hello World:

console.log(...) — prints to the terminal. Equivalent to System.out.println() in Java or print() in Python.

process — a global object in Node.js giving info about the running process:
process.version — Node.js version
process.platform — 'linux', 'win32', 'darwin'
process.argv — command-line arguments passed to your script

__filename — full path to the current file
__dirname — full path to the current directory

Comments in JavaScript:
// This is a single-line comment
/* This is a multi-line comment */
JavaScript ignores all comments — they are notes for humans only.
Code Example
// hello.js — your first Node.js program
 
// console.log prints to the terminal
console.log("Hello, World!");
console.log("Welcome to Node.js!");
 
// Node.js global objects
console.log('Node version:', process.version);
console.log('Platform:    ', process.platform);
console.log('File:        ', __filename);
console.log('Directory:   ', __dirname);
 
// Multiple values in one log
const name = "Alice";
const age  = 25;
console.log('Name:', name, '| Age:', age);
 
// Template literals (backtick strings) — like f-strings in Python
console.log(`Hello, ${name}! You are ${age} years old.`);
 
// console methods
console.log("Regular log");
console.warn("This is a warning");
console.error("This is an error");
console.table({ name: "Alice", age: 25, city: "Lagos" });
 
// Output:
// Hello, World!
// Welcome to Node.js!
// Node version: v20.x.x
// Platform:     linux
// Hello, Alice! You are 25 years old.
← Back to Course Variables, Data Types & Scope →

Log in to track your progress and earn badges as you complete lessons.

Log In to Track Progress