Congratulations, you made it to the end of the course! Dev’s boiler log digest now runs in JavaScript with the command node digest.js logs/week-44.log 75. It prints the same report as digest.py, from Peak flow temperature: 78.0 and Readings over 75.0: 2 to the lines for Wednesday’s 76.5 and Thursday’s 78.0, and it adds the week’s line to season.txt for Halden Heating.
In this course, you learned how to:
- Mark what a module shares with
export, and import it by its path,./and.jsincluded, as inimport { isBlank, parseLine, summarise } from "./readings.js"; - Tell a default import,
import formatReading from "./format.js", from a named one in braces, and import Node’s built-in modules from names such as"node:fs/promises" - Let the entry file’s top level be the program, and keep a self-check behind
if (import.meta.main)in a file that’s both a module and a script - Take the arguments with
process.argv.slice(2)and convert the limit withNumber() - Report a usage error with
console.error(), setprocess.exitCode = 1, and let the script finish instead of callingprocess.exit() - Read a whole file with
await readFile(path, "utf8"), and split it into lines withtext.trim().split("\n") - Add to a file with
appendFile(), write a whole one withwriteFile(), and build a tool’s own paths fromimport.meta.dirname
Keep the Habits That Carry Over
Much of your Python thinking still holds. A module has its own scope and executes once per run, however many files import it. The entry file is the one you hand to node, as you hand one to python. Arguments arrive as strings, standard error is for messages, and an exit code of zero means success. A relative path you pass to readFile() or appendFile() starts from the folder you run in, and a newline at the end of a line is still your job.