Up Next: Building Web APIs
Module 1 gave you Node's toolkit (running and debugging programs, modules and npm, files, arguments, settings and the event loop); this lesson shows which tool fits which job, the Expense Tracker CLI project that uses them all, and how Module 2 turns your code into a server.
Novice · Node.js · JavaScript · Updated
After this lesson you can
- Choose the Module 1 tool that fits a job, such as a module, an npm package, readFile, path.join, parseArgs, process.env or the debugger
Key takeaways
- Modules split a program into files, npm brings in other people's packages, and the debugger shows what your code is really doing.
- readFile, writeFile and path.join read and write files from any folder, and split and JSON.parse turn their text into data.
- parseArgs reads a command's options, process.env reads its settings, and console.error with process.exitCode reports a failure honestly.
- Module 2 turns your code into a server that waits for requests from browsers and apps and answers with JSON, one event loop serving them all.
You've finished the module that makes Node your own tool. You can run JavaScript outside the browser, split a program into modules, install packages, pause it in the debugger, and build a command that reads files, takes options and settings, and fails with a message a person can act on. This lesson puts those tools side by side, shows you the project that uses them all, and gives you a first look at Module 2.
What you can do now
| The tool | What it's for | Where you used it |
|---|---|---|
node, the REPL and node --watch |
Running a program, trying a line, restarting on every save | Exercise: Bakery Price Board |
map, filter, reduce and JSON |
Reshaping a list of records, totaling it, and saving it as text | Exercise: Food Truck Orders |
async and await, try and catch |
Waiting for slow work, and carrying on when it fails | Exercise: Food Truck Orders |
Modules, import and export |
Splitting a program into files that each do one job | Exercise: Book Club Picks |
npm and package.json |
Installing packages at pinned versions, and running scripts | Exercise: Book Club Picks |
| The debugger | Pausing a program to find the line where a value goes wrong | Debugging with Breakpoints |
readFile, writeFile, path.join |
Reading and writing files, from any folder | Exercise: Training Log |
parseArgs, process.env, process.exitCode |
Options, settings and an honest exit code | Exercise: Training Log |
Which tool fits?
When you plan a program, each part of the job points to a tool:
- A file that's grown too long, or code another file needs: split it into modules with
exportandimport. - A job someone has already solved well, such as reading a bank's CSV with quotes in it: install an npm package, at a pinned version.
- A wrong answer with no error message: set a breakpoint and use the debugger.
- Data kept between runs: read it with
readFile, save it withwriteFile, or add a line withappendFile. - A file that belongs to your program, wherever it's started from:
path.join(import.meta.dirname, ...). - Something the person chooses on each run, such as a runner or a month: an option, read with
parseArgs. - Something that's true of a whole computer, such as a data folder or a secret: an environment variable, read from
process.envwith a default. - Something went wrong: a message on
console.errorthat says what to do, andprocess.exitCode = 1.
The project: Expense Tracker CLI
Module 1's project is a command a friend can run on their own spending. Most banks let you download a month of your spending as a CSV file, and the Expense Tracker turns that file into a summary:
- the month's total, the total for each category (groceries, transport, eating out), the biggest expense and the busiest day;
- options to choose the month and one category, such as
--month 2026-10and--category groceries; - an optional default folder for the CSV files, read from an environment variable;
--out summary.txtto save the summary to a file;- a clear message and an exit code of 1 for a missing file or a row it can't read;
- tests, with
node --test, that check each function and run the tool as its own program.
It's your own project: you plan the files and write the code, and the data in its starter is made up, so you can try it before you point it at your own. Here's a taste, much smaller than the real thing, using only what this module taught:
const csv = `date,description,category,amount
2026-10-03,Corner Market,groceries,42.18
2026-10-05,Bus pass,transport,25.00
2026-10-12,Corner Market,groceries,37.60
2026-10-15,Pizza night,eating out,18.50`;
const [header, ...rows] = csv.split("\n");
const expenses = rows.map((row) => {
const [date, description, category, amount] = row.split(",");
return { date, description, category, amount: Number(amount) };
});
const byCategory = {};
for (const expense of expenses) {
byCategory[expense.category] = (byCategory[expense.category] ?? 0) + expense.amount;
}
const total = expenses.reduce((sum, expense) => sum + expense.amount, 0);
console.log(`Total: ${total.toFixed(2)}`);
for (const [category, amount] of Object.entries(byCategory)) {
console.log(` ${category}: ${amount.toFixed(2)}`);
}
Total: $123.28
groceries: $79.78
transport: $25.00
eating out: $18.50
Object.entries gives each of an object's names with its value, as pairs, so the loop can print every category. The real tool reads the CSV from a file and takes its month from an option, the way the Training Log does.
Up next: your code as a server
Every program you've written so far runs, does its job and ends. In Module 2, your code becomes a server: a program that keeps running and waits, and answers whenever a browser or a phone app sends it a request. The answers are JSON, the same text format you've been saving to files:
GET /plots?free=true
[{"number":2,"size":"small","gardener":null,"growing":null}]
That's a neighbor's phone asking a community garden's server for its free plots, and the server's answer. Module 2 starts with HTTP, the language those requests and answers are written in, then builds servers with Node's own http module and with Express, the framework most Node APIs use. The event loop from this chapter is what lets one server answer many neighbors at once, and the module ends with a library's book-loans API you can show working.
Check yourself
2 questions to try on the lesson page.
So what
Files, options, settings and honest errors make a script a tool someone else can use. Next, that tool learns to listen: a server that answers requests from anywhere.