Finish TaskKit: add a feature that fetches data from an API, and write a README
Look back at how TaskKit grew, ask the Nager.Date web API whether a due date is a public holiday, check its answer at the edge, let the feature step aside when the network is gone, and write TaskKit’s README in Markdown.
TypeScript
Fundamentals
Finish TaskKit: add a feature that fetches data from an API, and write a README. Read this lesson at .
Tested with TypeScript 7.x · Node.js LTS
It is Tuesday 27 October, and you are planning December. You add a
trip to the bank, due on 25 December, and TaskKit puts it on the
list: Go to the bank, due: Fri 25 Dec, in 59 days. Every word of
that line is right, and still, in many countries, you would find the
bank closed. 25 December is Christmas Day, a public holiday. A paper
calendar on the wall prints such days in red; TaskKit has no
calendar of its own, but a website does, and lesson 12.4 showed how a
program asks one.
This is the last module of Level 1. By the end of this lesson,
TaskKit asks a real web API (application programming interface: a
website that answers programs with data, lesson 12.4) whether a due
date is a public holiday and warns you when it is, and it has a
README: one page that lets someone who has never seen TaskKit
install it and use it.
How far TaskKit has come
In lesson 1.3 TaskKit was one file that printed its banner. Every
module since has added one thing, and each one stood on the ones
before it: the file (Module 12) saved the list (Module 4), the class
(Module 13) guarded the Map (Module 10), and the due dates needed
real commands (both in Module 14). Press Next layer to walk
through them, or let it play:
Module 1: a banner
node index.ts prints TaskKit 0.1.
Module 2: your words
Reads a command and a task you type.
Module 3: choices
Chooses by command, refuses a blank.
Module 4: a list
Keeps many tasks, sorted A to Z.
Module 5: functions
Small functions, and a first test.
Module 6: objects
Each task is an object with an id.
Module 7: a status
Each task is todo or done.
Module 8: errors
One clear line for a bad command.
Module 9: modules
Files, and npm start, check, test.
Module 10: a Map
Tasks kept in a Map<string, Task>.
Module 11: reminders
remind waits, then reminds you.
Module 12: a file
Saves tasks.json, asks for tasks.
Module 13: a class
A TaskStore class guards the tasks.
Module 14: libraries
Colours, real commands, due dates.
Module 15: holidays
Asks a web API; gets a README.
Fifteen modules, one new thing each; the last is this
lesson's
All 15 layers shown.Layer 1 of 15: Module 1: a bannerLayer 2 of 15: Module 2: your wordsLayer 3 of 15: Module 3: choicesLayer 4 of 15: Module 4: a listLayer 5 of 15: Module 5: functionsLayer 6 of 15: Module 6: objectsLayer 7 of 15: Module 7: a statusLayer 8 of 15: Module 8: errorsLayer 9 of 15: Module 9: modulesLayer 10 of 15: Module 10: a MapLayer 11 of 15: Module 11: remindersLayer 12 of 15: Module 12: a fileLayer 13 of 15: Module 13: a classLayer 14 of 15: Module 14: librariesLayer 15 of 15: Module 15: holidays
All 15 layers shown.
A web API of public holidays
Nager.Date is a free web API of public holidays for about two
hundred countries, and it needs no account. Like Open-Meteo in lesson
12.4, you ask it with an address:
Part
What it says
https://date.nager.at
Which computer to ask
/api/v3/PublicHolidays
Which service: the public holidays
/2026
Of which year
/UA
Of which country: Ukraine, by its two letters
This address has no query after a ?: the year and the country are
written into the address itself, between slashes. (Nager.Date's
website now calls itself Nager.Holidays, and its page shows a newer
version 4 address, with the country before the year. TaskKit asks
version 3, which still answers at this address.) Paste
https://date.nager.at/api/v3/PublicHolidays/2026/UA into your
browser's address bar. The answer is JSON (JavaScript Object
Notation, values written as text, lesson 12.1). Chrome shows it as
text, and you tick Pretty-print to lay it out; Firefox lays it out
for you. Either way, this answer is a list of 11 objects, one per
holiday. Here is the last one, laid out:
TaskKit needs two of those properties: date, written year, month,
day, the same way TaskKit writes its due dates (lesson 14.5), and
name, the holiday's English name. Now change UA to XX, which is
no country. The answer is a 404, the code for no such address in
HTTP (Hypertext Transfer Protocol, the rules for talking to websites,
lesson 12.4), with a body of another shape:
The answer for XXjson
{ "title": "Unknown country code", "status": 404, "detail": "The country code provided is invalid or not recognized."}
So, as with the weather in lesson 12.4, three things can happen: a
good answer, a bad answer, or no answer at all.
TaskKit asks about the date
The question belongs where a due date comes in: in add, when you
give --due. One rule decides how it is built. TaskKit worked well
without holidays, so asking about one must never stop it from adding
a task. The task is added and saved first, and only then does TaskKit
ask. Whatever goes wrong with the question ends in a yellow line,
never in a lost task.
Pick a run above the figure, 25 Dec, Offline or Code XX,
and press Next step to see where each one stops, or let it play:
store.add: reachedAdded: Go to the bank
fetch: passes✓Did any answer come back?
.ok: passes✓Is the status from 200 to 299?
.find: reachedFri 25 Dec is a public holiday: Christmas Day
The task is added first; each check that says no only
warns
All 6 steps shown.Step 1 of 6: store.addStep 2 of 6: fetchStep 3 of 6: fetch: passesStep 4 of 6: .okStep 5 of 6: .ok: passesStep 6 of 6: .find
All 6 steps shown.
store.add: reachedAdded: Go to the bank
fetch: stops here✕Did any answer come back?
.ok: never reachedIs the status from 200 to 299?
.find: never reachedFri 25 Dec is a public holiday: Christmas Day
TaskKit only warnsCould not check holidays: fetch failed
The task is added first; each check that says no only
warns
All 3 steps shown.Step 1 of 3: store.addStep 2 of 3: fetchStep 3 of 3: fetch: stops here. Could not check holidays: fetch failed
All 3 steps shown.
store.add: reachedAdded: Go to the bank
fetch: passes✓Did any answer come back?
.ok: stops here✕Is the status from 200 to 299?
.find: never reachedFri 25 Dec is a public holiday: Christmas Day
TaskKit only warnsCould not check holidays: HTTP 404
The task is added first; each check that says no only
warns
All 5 steps shown.Step 1 of 5: store.addStep 2 of 5: fetchStep 3 of 5: fetch: passesStep 4 of 5: .okStep 5 of 5: .ok: stops here. Could not check holidays: HTTP 404
All 5 steps shown.
Christmas Day and the country code XX are the two answers you saw in
the browser; no answer at all is lesson 12.4's third case. A date
that is not a holiday, 26 December, passes every check, and TaskKit
says nothing about it.
The rule comes down to where the try goes. Here is the function
that asks and warns, warnIfHoliday, written two ways, each run with
the network off. It calls holidayOn, which you write below in
holidays.ts: it asks Nager.Date about one date in one country and
gives back that day's holiday, or undefined. country holds the
country's two letters, and messageOf is TaskKit's helper from lesson
8.5 that turns any error into its message.
Bad — no try of its own, so a
missing network ends the whole command in red, and the list is never
printed.
index.tsts
async function warnIfHoliday(due: string): Promise<void> { const holiday = await holidayOn(due, country); if (holiday !== undefined) { const day = format(parseISO(due), "EEE d MMM"); const line = `${day} is a public holiday: ${holiday.name}`; console.log(chalk.yellow(line)); }}
Offline, under the banner, it prints:
Outputtext
Added: Go to the bankfetch failed
Good — its own try and catch, so
the failure is one yellow line, and TaskKit goes on.
index.tsts
async function warnIfHoliday(due: string): Promise<void> { try { const holiday = await holidayOn(due, country); if (holiday !== undefined) { const day = format(parseISO(due), "EEE d MMM"); const line = `${day} is a public holiday: ${holiday.name}`; console.log(chalk.yellow(line)); } } catch (error) { const line = `Could not check holidays: ${messageOf(error)}`; console.log(chalk.yellow(line)); }}
Offline, under the banner, it prints:
Outputtext
Added: Go to the bankCould not check holidays: fetch failed1 task added, room for 4 moreList 20% fullYour list, by due date:#1 [todo] Go to the bank, due: Fri 25 Dec, in 59 days
In the Bad version the error travels up to the catch around
parseAsync, which prints it in red and skips the summary and the
list. The task was saved, but a red line and no list make it look as
if the command failed, so you add it again and get
Already on the list: Go to the bank.
1
Ask in holidays.ts
Make a new file, holidays.ts, in the taskkit folder:
holidays.tsts
export interface Holiday { date: string; name: string;}export function holidaysFrom(data: unknown): Holiday[] { if (!Array.isArray(data)) { throw new Error("the answer is not a list"); } const holidays: Holiday[] = []; for (const item of data) { const entry: unknown = item; if ( typeof entry !== "object" || entry === null || !("date" in entry) || !("name" in entry) ) { throw new Error("a holiday without a date or a name"); } const date: unknown = entry.date; const name: unknown = entry.name; if (typeof date !== "string" || typeof name !== "string") { throw new Error("a date or a name that is not text"); } holidays.push({ date: date, name: name }); } return holidays;}export async function holidayOn( due: string, country: string): Promise<Holiday | undefined> { const year = due.slice(0, 4); const url = `https://date.nager.at/api/v3/PublicHolidays/${year}/${country}`; const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP ${response.status}`); } const data: unknown = await response.json(); return holidaysFrom(data).find((holiday) => holiday.date === due);}
holidaysFrom is the check at the edge from lesson 12.5, for a list
this time. Array.isArray asks whether the answer is a list at all.
After it, each item of the list is typed any (lesson 12.5), so line
12 puts it into a box typed unknown, and the questions on lines 14
to 17 ask what lesson 12.5's asked: an object, not null, with a
date and a name. Line 23 lets only text through. What comes out
is a Holiday[] that TypeScript can trust, because every item was
looked at.
holidayOn asks the question. The year is the first four characters
of the due date, so "2026-12-25".slice(0, 4) is "2026", and the
address is built from it and the country. Line 39 is the status check
from lesson 12.4. At the end, find (lesson 4.3) looks for the
holiday whose date is the due date. When none is, find gives
undefined, which is why the function promises a
Holiday | undefined.
2
Test holidaysFrom
The test should not ask Nager.Date: a test that needs the internet
fails on a train, and its answer could change. It hands
holidaysFrom an answer written into the test instead. Make
holidays.test.ts:
holidays.test.tsts
import { test } from "node:test";import assert from "node:assert/strict";import { holidaysFrom } from "./holidays.ts";test("holidaysFrom keeps each date and name", () => { const holidays = holidaysFrom([ { date: "2026-12-25", name: "Christmas Day", global: true }, ]); assert.equal(holidays[0].date, "2026-12-25"); assert.equal(holidays[0].name, "Christmas Day");});
Real holidays have nine properties; this one has three.
holidaysFrom copies only the two TaskKit reads.
3
Warn in index.ts
At the top of index.ts, import holidayOn, and add format to the
date-fns import:
index.tsts
import { isValid, parseISO } from "date-fns";import { format, isValid, parseISO } from "date-fns";
index.tsts
import { holidayOn } from "./holidays.ts";
Under const version = "0.1";, say which country's holidays to ask
about:
index.tsts
const country = "UA";
UA is Ukraine. Keep it while you follow this lesson, so your output
matches the one below; at the end you switch to your own country.
Then, beside remindLater, add the Good warnIfHoliday from above,
the one with its own try and catch. Last, call it at the end of
add's action, after the save:
Your list from lesson 14.6 is full, so start an empty one. Delete
tasks.json, then:
bash
npm run checknpm start -- add --due 2026-12-25 "go to the bank"npm test
The check prints only its two > lines. Under the banner, the add
prints:
Outputtext
Added: Go to the bankFri 25 Dec is a public holiday: Christmas Day1 task added, room for 4 moreList 20% fullYour list, by due date:#1 [todo] Go to the bank, due: Fri 25 Dec, in 59 days
The second line is yellow, and your days left will differ. The tests
end with ℹ pass 19 and ℹ fail 0: the 18 from before, and the new
one.
Write a README
In lesson 14.1 you chose packages by reading their readmes: what the
package does, how to install it, how to call it. TaskKit is a project
too, and anyone who opens its folder meets a dozen files and not a
word about which one to run. A README is the page that tells them.
Everyone names it README.md, in capitals so that it stands out, and
it sits in the project's top folder. npm shows a package's README on
its page, and so does GitHub, a website where people keep and
share their code, which is where TaskKit goes in lesson 15.3.
The .md stands for Markdown: plain text with a few marks that
say how it should look. In your editor it stays text; on GitHub, and
in the preview of VS Code (Visual Studio Code, your editor), the marks
turn into headings, lists and code.
TaskKit's README needs six of them:
You write
It shows
# TaskKit
The page's title
## Install
A section heading
- `add` adds tasks
One point of a list
`npm ci`
Code inside a sentence
Three backticks and bash, the code, three backticks
A block of code
[Nager.Date](https://date.nager.at/Api)
A link
The word right after the first three backticks names the language of
the code, here bash for terminal commands, so that it is coloured
the right way. A good README answers, in order, the questions a
stranger has: what is this, how do I get it running, how do I use it,
how do I check it. Make README.md in the taskkit folder:
README.mdmd
# TaskKitYour tasks, in your terminal. TaskKit keeps a short list of tasks ina file, with due dates, and warns you when a task is due on a publicholiday.## InstallYou need Node.js 24 or newer. In this folder, run:```bashnpm ci```## Use```bashnpm start add "buy milk"npm start -- add --due 2026-12-25 "go to the bank"npm start remind "call Mom"npm start help```- `add` adds tasks; with no task, TaskKit asks for them.- `--due` sets a due date, written year-month-day.- `remind` reminds you of a task two seconds later.## Check and test```bashnpm run checknpm test```## ThanksPublic holidays come from [Nager.Date](https://date.nager.at/Api), afree web API.
Every command in it is one you ran in this course, and help prints
the list commander writes from your descriptions (lesson 14.4). The
## Thanks section names the API: TaskKit's newest feature works
because someone else runs Nager.Date for free, and saying so is how
projects repay that.
To see the README much as GitHub will show it, open README.md in VS
Code and press these keys:
⌘ Cmd+⇧ Shift+V
Ctrl+Shift+V
Ctrl+Shift+V
VS Code's Markdown preview, in the same tab. Press the same keys again
to go back to the text.
The preview shows TaskKit as a large title, four headings, a list
with code in it, and the link in colour. If a heading shows its #,
the mark needs a space after it: ## Install, not ##Install.
Predict before you run
You plan to buy champagne on 1 January:
Predict
Which line does TaskKit print right under Added: Buy champagne?
bash
npm start -- add --due 2027-01-01 "buy champagne"
The common mistake: a README for one computer
Your taskkit folder has node_modules in it, filled by every
npm install since Module 9. It is big: nearly 50 MB (megabytes) in
some 8,000 files, more than all of TaskKit's own code many times over.
And it adds nothing a stranger cannot make: npm ci (clean install)
rebuilds it exactly from package-lock.json (lesson 14.2). So when a
project is shared, node_modules is left out on purpose, and lesson
15.2 leaves it out too. A README that starts at npm start then works
on your computer and on no one else's.
Common mistake
A README with no install step
The README's first command is
bash
npm start add "buy milk"
and in a copy of the folder with no node_modules, Node stops on the
first line of index.ts:
What Node printstext
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chalk'imported from /Users/ana/projects/taskkit/index.ts
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chalk'imported from C:\Users\ana\projects\taskkit\index.ts
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chalk'imported from /home/ana/projects/taskkit/index.ts
The error is one long line in your terminal, broken here to fit. Above
it Node prints a few lines from inside itself, and under it a stack
trace. chalk is named because it is the first package index.ts
imports, on its first line; Node never gets to the others.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chalk' imported from …/taskkit/index.ts
The fix
Put the install step first, as TaskKit's README does:
bash
npm cinpm start add "buy milk"
To see what a stranger sees, right-click node_modules in the panel
on the left of VS Code and choose Delete; VS Code asks whether you
are sure, so press Move to Trash on macOS and Linux, or Move to
Recycle Bin on Windows. Run npm start add "buy milk": you get the
error above. Then follow your own README from the top. npm ci
rebuilds node_modules from the lockfile and ends like this, with
numbers of your own (ms is short for milliseconds, thousandths
of a second):
Outputtext
added 24 packages, and audited 25 packages in 972ms15 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilities
and TaskKit runs again. A README is finished when you can follow it,
word for word, in a copy with no node_modules.
Pass all three tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
Exercises
The page cannot show a Markdown preview or reach Nager.Date, so the
README is written as console.log lines, and the code gets its
answers written out, as the test does.
Exercise · Fix the error
Three marks that show as plain text
Each line this program prints is a line of a README with one mistake
in its Markdown, so the preview would show the marks instead of a
heading, code and a link. Fix the three lines.
Loading the editor…
Exercise · Fix the error
A name that is not text
This holidaysFrom forgot one question, and TypeScript refuses line
26: Type 'unknown' is not assignable to type 'string'. Add the
missing question, so that TypeScript accepts line 26 and the program,
handed a holiday whose name is a number, prints
a date or a name that is not text.
Loading the editor…
Exercise · Write the code
The address for a due date
Write holidaysUrl. It gets a due date and a country's two letters,
and gives back the Nager.Date address for the public holidays of that
date's year.
Loading the editor…
Recap
Recap · 3 questions
Check yourself
Why does TaskKit add the task before it asks about holidays?
Check yourself
Why does the test hand holidaysFrom an answer written out?
Check yourself
Why does TaskKit's README start with npm ci?
0 of 0 answered.
A cheat sheet to keep
Cheat sheet
Finish TaskKit: an API feature and a README
What things are
Word
What it means
Nager.Date
A free web API of public holidays, no account
README
The page that says what a project is and how to run it
Markdown
Plain text whose marks become headings, lists and code
README.md
The README's file name, in the project's top folder
GitHub
A website where people keep and share their code
Code
Write
What you get
PublicHolidays/2026/UA
Ukraine's public holidays in 2026
due.slice(0, 4)
The year of a due date, "2026"
holidaysFrom(data)
A Holiday[], or an error saying what is wrong
try in warnIfHoliday
A failure is a yellow line, not a red end
Markdown
You write
It shows
# Title, ## Section
The title, a section heading
- point
One point of a list
`code`
Code inside a sentence
Three backticks and bash
A block of code, coloured as bash
[text](address)
A link
Rules
Rule
What it means
Extra features step aside
Save the task first, then ask the API
Tests never call the network
Hand holidaysFrom an answer written out
Install comes first
A README starts with npm ci
Follow your own README
In a copy with no node_modules
Where to go next
You can now add a feature that asks a web API, keep its answer behind
a check at the edge, make it step aside when the network is gone, and
write a README in Markdown that a stranger can follow.
Next is Git on your computer: commits and a .gitignore, the
second lesson of Module 15, where Git saves the taskkit folder, this
README included, as its first commit, and leaves out node_modules
and your own list. Lesson 15.3 then puts it on GitHub.
Before you move on, find a public holiday of your own country in the
browser (https://date.nager.at/api/v3/PublicHolidays/2026/ and your
two letters), set country to them, and add a task due on that day.
Then add ## Public holidays to the README, saying which country
TaskKit asks about and how to change it.