Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Porting the Three-Plant Digest

The three-plant digest keeps its responsibilities in separate modules: the package entry forwards its public tools, settings owns the plant list and verbose flag, the reader uses the selected parser, and the chart remains optional. Keep Halden’s supplied fault file as CommonJS and import it through its .cjs filename.

The complete runnable source accompanies the video. Run both versions on the same week and compare the entire report, including faults. The verbose option adds a skipped-line diagnostic on standard error; it does not add missing readings to the report or chart. With these peaks, both versions produce the same text chart.

Check each JavaScript source with node --check. A successful syntax check prints nothing. With no week folder, the programs show usage on standard error and return status one. Next up: Finish the Three-Plant Digest, where you’ll complete the entry script’s report.

00:00 You’ll connect the school’s digest into one JavaScript program. The main boiler, sports hall, and science block keep their existing logs. The Python package already separates jobs into modules.

00:11 Your port keeps those boundaries and checks the same report. You’ll review the connections before practicing the entry script. In Python, the package imports its public names.

00:23 In JavaScript, the entry file forwards the controller loader, readings tools, and plant loader. The caller names that file, rather than the folder. The package’s alias gives its modules the same internal address from any depth.

00:38 Those paths now connect the whole package.

00:43 In Python, settings finds the plant list beside its file. In JavaScript, the JSON import keeps that same neighbor and declares its type. Both versions expose the plant list through a loader.

00:56 The JavaScript settings module also owns the verbose flag; its exported setter changes that flag for the log reader.

01:05 The plant’s controller name selects its parser module at runtime. Python returns a module; JavaScript’s import expression resolves to a module namespace after the caller awaits it.

01:17 Halden’s parser uses the contractor’s fault file, kept as CommonJS. Ostra’s parser marks its missing sensor reading with null. The reader can treat both parsers alike.

01:30 In Python, the reader opens the log and enumerates its lines. In JavaScript, it awaits the file text, splits the lines, and uses .entries() for their positions.

01:41 Both versions pass each line to the selected parser. An accepted reading joins the readings array; the controller’s input format stays outside this reader.

01:54 The missing Ostra reading is skipped in both versions. In JavaScript, the shared verbose binding enables its diagnostic on standard error. The displayed line number adds one to the array position.

02:06 After reading, Python’s max() finds the maximum. JavaScript’s .map() collects the temperatures; spread passes them as separate arguments to Math.max().

02:18 Then .filter() keeps readings above the plant’s limit, like Python’s comprehension. The same accepted readings produce each plant’s peak and over-limit rows.

02:30 The chart consumes the same peaks as the report. Python pads each plant name; JavaScript uses padding and repeats the bar marks. These three values round to the same bar lengths in both versions.

02:43 The caller loads the chart only in its option branch, using the import expression already used for conditional loading.

02:51 The caller turns verbose on through its setter before reading any log. With both options in this command: trace the missing-reading branch into the chart’s input.

03:07 The reader still skips that reading. Verbose adds a diagnostic. The chart keeps the same accepted peaks.

03:18 Run both programs on week twelve without options. Their standard output matches. The main boiler has two over-limit readings, the sports hall has one, and the science block has one.

03:31 The fault section still names the main boiler’s low-water-pressure reading. Those are the report’s complete nine lines.

03:41 With both options, the skipped-line message appears on standard error before the science result. The report is unchanged. The chart then follows the faults, with one row for each plant.

03:54 Python and JavaScript produce the same chart rows for this week. Standard output and diagnostics keep their separate jobs.

04:05 Check every JavaScript source file with the syntax-check command. All checks pass. Without a week folder, both programs show their usage on standard error and return status one.

04:17 Your rule is to keep module ownership clear and verify the whole program. Next up: Finish the Three-Plant Digest, where you’ll complete the entry script’s report.

Become a Member to join the conversation.