Node.js Web Basics Tutorial

From Hello World to REST APIs

This tutorial takes you from running your first Node.js script to building a complete REST API. Each module builds on the previous one, showing you how Node.js web development works from the ground up.

Unlike PHP (which runs inside a web server), Node.js applications create their own HTTP servers. You'll learn what that means and how to leverage it.

Tutorial Modules

01. Hello World

Understand Node.js fundamentals: running scripts, ES6+ features, and the event loop.

  • Running JavaScript with Node
  • The event loop concept
  • Callbacks and async patterns
Start Module

02. HTTP Server

Build a web server from scratch using Node's built-in http module.

  • http.createServer()
  • Request and response objects
  • Manual routing and file serving
Start Module

03. Express Basics

The Express framework: routing, middleware, and static files.

  • npm and package management
  • Express routing
  • Serving static files
Start Module

04. Form Handling

Process GET and POST data, parse request bodies.

  • req.query and req.body
  • Body parsing middleware
  • Comparison with PHP
Start Module

05. REST API

Build a simple RESTful API with CRUD operations.

  • REST principles
  • HTTP verbs and resources
  • JSON responses
Start Module

06. Database Setup

Connect to PostgreSQL. Build CRUD with parameterized queries.

  • PostgreSQL and node-postgres
  • Parameterized queries
  • SQL injection prevention
Start Module

07. Server-Side MVC

Build a full CRUD web app with Express, EJS templates, and PostgreSQL.

  • Model, View, Controller structure
  • EJS template engine
  • POST/Redirect/GET pattern
Start Module

08. Client-Side MVC

Build the same CRUD app as a SPA. Express serves JSON; JavaScript renders everything.

  • fetch() for all CRUD operations
  • Client-side DOM rendering
  • textContent for XSS prevention
Start Module Try Demo

09. Adaptable MVC

Combine both approaches. The controller serves HTML or JSON based on the Accept header. Progressive enhancement.

  • Content negotiation (Accept header)
  • Progressive enhancement with enhance.js
  • Works with and without JavaScript
Start Module

Running the Demos

Prerequisites: You need Node.js installed. Check with:
node --version

If not installed, download from nodejs.org

Quick Reference

PHP Node.js (Express)
$_GET['name'] req.query.name
$_POST['email'] req.body.email
$_SERVER['REQUEST_METHOD'] req.method
header('Content-Type: ...') res.set('Content-Type', '...')
echo json_encode($data) res.json(data)

Back to CSE 135 Home | Node.js Overview | Start Tutorial