Week 7: Node.js & Express Fundamentals

Backend

Introduction to server-side development with Node.js and Express.js framework.

Learning Objectives

Detailed Schedule

Session 1: Node.js Fundamentals (1 hour)

Node.js Basics (25 minutes)

  • Node.js runtime environment
  • Event-driven architecture
  • Non-blocking I/O operations
  • Node.js module system

Package Management (20 minutes)

  • npm and package.json
  • Installing and managing dependencies
  • Scripts and automation

Practice Exercise (15 minutes)

Set up a Node.js project and create basic server scripts

Session 2: Express.js Framework (1 hour)

Express Setup (25 minutes)

  • Express.js framework introduction
  • Setting up Express application
  • Middleware concepts
  • Route handling and HTTP methods

Advanced Express (20 minutes)

  • Custom middleware creation
  • Error handling middleware
  • Static file serving

Practice Exercise (15 minutes)

Build a RESTful API with Express.js and middleware

Session 3: API Development (1 hour)

RESTful API Design (25 minutes)

  • REST principles and conventions
  • HTTP status codes and responses
  • API endpoint design
  • Request/response handling

Data Handling (20 minutes)

  • JSON data processing
  • Request body parsing
  • Query parameters and validation

Practice Exercise (15 minutes)

Create a complete RESTful API with CRUD operations

Key Concepts

Node.js

  • • Event-driven architecture
  • • Non-blocking I/O
  • • Module system
  • • Package management

Express.js

  • • Routing and middleware
  • • Request/response handling
  • • Static file serving
  • • Template engines

REST APIs

  • • HTTP methods and status codes
  • • CRUD operations
  • • API design principles
  • • Data validation

Middleware

  • • Request processing pipeline
  • • Custom middleware
  • • Error handling
  • • Security middleware

Hands-on Activities

Activity 1: Basic HTTP Server

Create a simple HTTP server using Node.js built-in modules to handle different routes and responses.

HTTP Module Routing File System

Activity 2: Express Application

Build a basic Express application with multiple routes and middleware for request processing.

Express.js Routing Middleware

Activity 3: Custom Middleware

Develop custom middleware for logging, authentication, and error handling.

Custom Middleware Logging Error Handling

Activity 4: RESTful API

Create a complete RESTful API with CRUD operations, proper HTTP status codes, and data validation.

REST API CRUD Operations Validation

Weekly Project: Task Management API

Project Overview

Build a complete Task Management API with Node.js and Express.js, implementing all CRUD operations and proper error handling.

API Endpoints:

  • GET /tasks - Get all tasks
  • POST /tasks - Create new task
  • GET /tasks/:id - Get specific task
  • PUT /tasks/:id - Update task
  • DELETE /tasks/:id - Delete task
  • GET /tasks/status/:status - Filter by status

Technical Requirements:

  • Express.js server setup
  • RESTful API design
  • Middleware implementation
  • Error handling and validation
  • Data persistence (JSON file)
  • API documentation

Project Structure:

task-management-api/
├── src/
│   ├── routes/
│   │   └── tasks.js
│   ├── middleware/
│   │   ├── errorHandler.js
│   │   ├── logger.js
│   │   └── validator.js
│   ├── utils/
│   │   └── dataManager.js
│   └── app.js
├── data/
│   └── tasks.json
├── package.json
└── README.md

Assessment Criteria

Technical Skills (60%)

  • Node.js server setup (15%)
  • Express.js implementation (20%)
  • RESTful API design (15%)
  • Middleware and error handling (10%)

Project Quality (40%)

  • API functionality and completeness (15%)
  • Code organization and structure (15%)
  • Error handling and validation (10%)

Teaching Resources