JavaScript · Advanced level

Advanced level · Module 2 of 6 · 24 guided hours

Node.js for Tools and Servers

Use Node.js to work with files, build command-line tools and write a small HTTP API with validation.

Learning objectives

  • Use Node.js modules, npm packages and the file system
  • Build command-line tools that process data files
  • Build and test a small HTTP JSON API

Topics

  • Node.js runtime and modules
  • npm packages and semantic versioning
  • fs/promises and streams
  • command-line arguments
  • http module and routing
  • input validation and status codes

Lessons

  1. Lesson 1 The Node.js Runtime and npm

    Understand what Node.js adds to JavaScript, use built-in modules and manage packages and versions with npm.

    built-in modules (node:fs, node:path)npm installsemantic versioningpackage-lock.json

  2. Lesson 2 Files, Data and Command-Line Tools

    Read and write files, process CSV and JSON data and build command-line tools with arguments and exit codes.

    fs/promisesprocess.argv and util.parseArgsexit codesstreams for large files

  3. Lesson 3 Building an HTTP API with Node.js

    Create a small JSON API with node:http or a minimal framework, with routing, status codes and headers.

    http.createServerroutingstatus codesJSON request bodies

  4. Lesson 4 Validating and Testing the API

    Validate every input on the server, return useful errors and test the API automatically.

    server-side validationerror response formatintegration testtest server on a random port

Practical activity

Build a CLI that summarises a CSV of payments, then expose the same summary through a small JSON API with validation and tests.

Expected outcomes

  • Useful Node.js tools
  • A tested JSON API

Assessment

Practical: implement a CLI command and an API endpoint for a provided data set; marked by tests and behaviour with invalid input.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.