Node.js from a script to an API
Understand where JavaScript runs, then learn modules, async work, files, HTTP, validation and tests before building an API.
Prerequisite: JavaScript foundations: functions, objects, arrays and callbacks. No TypeScript required. · 161 minutes of guided study
Start here before the intermediate framework labs. Each example is self-contained; replace the previous example instead of pasting them together.
Start first lesson →What you’ll be able to do
- Run a JavaScript file outside the browser
- Understand imports and explicit exports
- Wait for a promise without blocking JavaScript
- Read and validate a JSON file
- Receive an HTTP request and return JSON
- Validate a query parameter at the boundary
- Write repeatable tests for the logic
- Project · A small searchable topics API
How to study this course
Follow the numbered modules. Read the example, explain why it works, attempt the exercise, then compare your result with the supplied checks.
Setup: Install Node.js 22.12+ (or a supported newer LTS). Create a folder named codingneed-node. Open a terminal in that folder. Save ONE lesson example as lesson.mjs and run node lesson.mjs. No npm dependencies are required. HTTP lessons keep running until you press Ctrl+C; stop the previous server before starting another.
Times estimate guided reading and practice. Projects and revision can take longer.
Course syllabus · 8 lessons
1 · Get comfortable
2 · Build one skill at a time
- Wait for a promise without blocking JavaScript18 min · Project environment →
Await pauses an async flow until a promise settles.
- Read and validate a JSON file18 min · Project environment →
Reading bytes, parsing JSON and validating data are separate steps.
- Receive an HTTP request and return JSON18 min · Project environment →
A server maps a request method and path to a response.
3 · Connect, test and build
- Validate a query parameter at the boundary18 min · Project environment →
Treat URL values as untrusted strings before using them.
- Write repeatable tests for the logic18 min · Project environment →
A test should check behavior, including boundaries and failures.
- Project · A small searchable topics API35 min · Project environment →
Connect a pure function to a thin, validated HTTP handler.