Node.js Overview

JavaScript on the Server

"Node.js IS the server. Unlike PHP which runs inside Apache, a Node.js application creates its own HTTP server and runs continuously."

CSE 135 — Full Overview | Review Questions

Section 1The Fundamental Difference

PHP processes requests and exits. Node.js runs continuously.

PHP vs Node.js Execution Model

PHP Model (per-request): Node.js Model (persistent process): Browser ──▶ Apache ──▶ PHP Browser ──────────────────────▶ Node.js │ │ │ │ Process starts Process runs │ │ continuously │ Handle request │ │ │ app.listen(3000) │ Process ends │ ▼ ▼ ▼ Response sent Handles many requests without restarting

PHP runs inside Apache — a new process per request. Node.js IS the server — one process handling all requests continuously.

Four Key Implications

  • State persists: Variables stay in memory between requests (unlike PHP where everything resets)
  • No cold start: The server is already running, no process spawn overhead
  • Single-threaded event loop: One thread handles many concurrent connections
  • You control the server: You write the code that listens for HTTP requests
This is the single most important difference. PHP's per-request model means no shared state, automatic cleanup, and Apache handles concurrency. Node.js gives you more power — and more responsibility.

Section 2Tutorial Modules

Five hands-on modules from Hello World to REST APIs.

Learning Path: 5 Modules

ModuleFocusKey Topics
01. Hello WorldNode.js fundamentalsRunning scripts, ES6+ features, the event loop, callbacks & async
02. HTTP ServerBuilding from scratchhttp.createServer(), request/response objects, manual routing
03. Express BasicsThe Express frameworknpm & packages, Express routing, static files, middleware
04. Form HandlingProcessing user inputreq.query, req.body, body parsing middleware, PHP comparison
05. REST APIRESTful CRUDREST principles, HTTP verbs & resources, JSON responses
The modules build progressively: bare Node.js (01–02) teaches what Express abstracts away, so Express (03–05) makes sense rather than feeling like magic.

Section 3Quick Comparison: PHP vs Node.js

Same web problems, fundamentally different approaches.

PHP vs Node.js — 8 Dimensions

AspectPHPNode.js
ExecutionPer-request (process starts/stops)Persistent (runs continuously)
ServerRuns inside Apache/nginxIS the server (creates own HTTP listener)
ConcurrencyMultiple processes/threadsSingle-threaded event loop
GET parameters$_GET['name']req.query.name
POST body$_POST['email']req.body.email
SessionsBuilt-in ($_SESSION)Requires middleware (express-session)
Package managerComposernpm
Best forTraditional websites, CMSsAPIs, real-time apps, microservices
PHP runs per-request inside Apache. Node.js IS the server, runs continuously. This single architectural difference explains every row in the table above.

Running the Demos

Local Development: Run demos with Node.js directly:
cd node-tutorial/01-hello-world node hello.js # For Express demos, install dependencies first: cd node-tutorial/03-express-basics npm install node app.js
Unlike PHP, Node.js demos don't run through Apache. You start the server yourself with node. The process stays running until you press Ctrl+C. Each demo listens on its own port (usually 3000).

Section 5Node.js Quick Reference

Core modules, bare HTTP server, and Express basics.

Core Modules

const http = require('http'); // HTTP server const fs = require('fs'); // File system const path = require('path'); // Path utilities const url = require('url'); // URL parsing

These are built-in — no npm install needed. They ship with Node.js and provide the foundation for everything else.

What Each Module Does

  • http: Create servers, make HTTP requests — the core of web development in Node
  • fs: Read/write files, watch for changes — replaces PHP's file_get_contents
  • path: Join, resolve, and normalize file paths cross-platform
  • url: Parse and format URLs — extract query strings, hostnames, paths

Bare HTTP Server vs Express

Basic HTTP Server

const http = require('http'); const server = http.createServer( (req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World!'); }); server.listen(3000, () => { console.log('Server on :3000'); });

Express

const express = require('express'); const app = express(); app.use(express.json()); app.use(express.urlencoded( { extended: true } )); app.use(express.static('public')); app.get('/', (req, res) => { res.send('Hello World!'); }); app.get('/api/users/:id', (req, res) => { res.json({ id: req.params.id }); }); app.listen(3000);
Express abstracts the http module boilerplate. Routing, body parsing, static files, and JSON responses are built in. The bare server teaches you what Express does under the hood.

SummaryKey Takeaways

5 concepts of Node.js server-side development in one table.

Node.js Overview at a Glance

ConceptKey Takeaway
Execution ModelNode.js IS the server — one persistent process handles all requests. PHP spawns a process per request inside Apache.
Tutorial Modules5 progressive modules: bare Node (01–02) teaches fundamentals, Express (03–05) adds the framework layer.
PHP ComparisonSame web problems, different architectures. PHP: per-request, built-in features. Node: persistent, middleware ecosystem.
Running DemosRun with node file.js directly — no Apache needed. The process stays running until you stop it.
Quick ReferenceCore modules (http, fs, path, url) are built-in. Express adds routing, middleware, and JSON/form parsing.