Tutorial Template (Diátaxis)
Diátaxis tutorial – learning goals, prerequisites, numbered lessons with visible results, checkpoints, troubleshooting
How to use: Use for a guided lesson where a beginner builds something real. Write the end result and lesson steps first, each with the result the learner should see, then test on a clean machine. The main pitfall is offering choices or long explanations mid-lesson.
Preview
Tutorial: Build [your first thing] with [Product name]
Learning-oriented tutorial in the Diátaxis sense: a guided lesson in which the reader builds something real, step by step, and sees a result after every step. Adapted from the Diátaxis framework by Daniele Procida (CC BY-SA 4.0). Replace every
[bracketed]value and every passage marked Example.
| Field | Value |
|---|---|
| Level | [Beginner / Intermediate / Advanced] |
| Time to complete | [About 30 minutes] |
| Tested with | [Product name 2.3, Node.js 22.11, macOS 15 and Ubuntu 24.04] |
| Author | [@name] |
| Last tested | YYYY-MM-DD |
What you will learn
In this tutorial you will build [a small weather dashboard that shows the current temperature for any city]. Along the way you will learn to:
- [Create a new project from the starter template.]
- [Fetch data from an API and display it on a page.]
- [Handle a failed request and show a helpful message.]
- [Deploy the result so you can share a link.]
Before you begin
You need:
- Basic familiarity with [a terminal and a text editor]. You do not need to know [JavaScript frameworks]; the tutorial shows every line.
- [Node.js 22 or later]. Check with
node --version; you should seev22or higher. - A free [Product name] account. Sign up at [https://example.com/signup].
- About [30] minutes without interruptions.
How to follow this tutorial: do every step in order, type or paste the
code exactly as shown, and compare what you see with the result described
under each step before you move on. If your result differs, stop and use
the Troubleshooting table; continuing usually makes
the problem harder to find. Text in monospace is something you type or
see in the terminal; bold text is something you see or select on screen.
What you will build
At the end you will have a page that looks like this when you search for a city:
+----------------------------------+
| Weather |
| [ Lisbon ] [Search] |
| |
| Lisbon, Portugal |
| 19 °C, light clouds |
+----------------------------------+
The pieces fit together like this:
Lesson 1: Create the project
-
Open a terminal and create the project from the starter template:
npx create-[product]-app weather-dashboardYou should see
Success! Created weather-dashboardafter about a minute. -
Move into the new folder and start the development server:
cd weather-dashboard npm run devThe terminal shows
Local: http://localhost:3000. -
Open
http://localhost:3000in your browser.You should see a page that says Welcome to [Product name].
Checkpoint: You have a running project. Leave the server running for the rest of the tutorial; it reloads the page every time you save a file.
Lesson 2: Add the search form
-
Open
src/page.tsxin your editor and replace its contents with:export default function Page() { return ( <main> <h1>Weather</h1> <form> <input name="city" placeholder="City name" /> <button type="submit">Search</button> </form> </main> ); } -
Save the file.
The browser reloads and shows the heading Weather, a text box and a Search button.
-
Type
Lisbonand select Search.The page reloads and the text box is empty again. That is expected: the form does not do anything yet. You will connect it in the next lesson.
Checkpoint: Your page has a working form that you can type into.
Lesson 3: Fetch the weather
-
In your [Product name] dashboard, go to API keys, select Create key, and copy the key.
-
Create a file named
.env.localin the project folder with this line, pasting your key after the equals sign:WEATHER_API_KEY=[your-key] -
Stop the server with
Ctrl+Cand start it again withnpm run dev, so that it reads the new file. -
Replace
src/page.tsxwith the version that fetches data:async function getWeather(city: string) { const res = await fetch( `https://api.example.com/v1/current?city=${encodeURIComponent(city)}`, { headers: { Authorization: `Bearer ${process.env.WEATHER_API_KEY}` } }, ); if (!res.ok) throw new Error(`Request failed: ${res.status}`); return res.json() as Promise<{ name: string; temp_c: number; summary: string }>; } export default async function Page({ searchParams }: { searchParams: Promise<{ city?: string }> }) { const { city } = await searchParams; const weather = city ? await getWeather(city) : null; return ( <main> <h1>Weather</h1> <form> <input name="city" placeholder="City name" defaultValue={city} /> <button type="submit">Search</button> </form> {weather && <p>{weather.name}: {weather.temp_c} °C, {weather.summary}</p>} </main> ); } -
Save the file, type
Lisbonand select Search.Below the form you should see a line such as Lisbon: 19 °C, light clouds. The numbers will differ; the shape of the line should match.
Checkpoint: Your page shows live data. Notice that the address bar now
contains ?city=Lisbon; the form sends the city in the URL.
Lesson 4: Handle a failed request
-
Search for
Xyzzyville, a city that does not exist.The page shows an error screen. This is what users would see today.
-
In
src/page.tsx, change the line that callsgetWeatherto catch the error:const weather = city ? await getWeather(city).catch(() => "not-found" as const) : null;and replace the paragraph line with:
{weather === "not-found" && <p>We could not find that city. Check the spelling.</p>} {weather && weather !== "not-found" && <p>{weather.name}: {weather.temp_c} °C, {weather.summary}</p>} -
Save and search for
Xyzzyvilleagain.You should now see We could not find that city. Check the spelling.
Checkpoint: Your page handles both success and failure.
Lesson 5: Deploy and share
-
Stop the server and run:
npx [product] deploy -
When asked, add
WEATHER_API_KEYas a secret and paste your key.After about a minute the terminal prints a URL such as
https://weather-dashboard-ab12.example.app. -
Open the URL on your phone and search for your own city.
Checkpoint: Your dashboard is live on the internet.
Troubleshooting
| What you see | Likely cause | What to do |
|---|---|---|
command not found: npx | Node.js is not installed or not on the path | Install Node.js 22 and open a new terminal |
| Page still shows Welcome after Lesson 2 | File saved in the wrong folder | Check the path is weather-dashboard/src/page.tsx |
Request failed: 401 | API key missing or not loaded | Check .env.local, then restart the server (Lesson 3, step 3) |
| Port 3000 is already in use | Another server is running | Stop it, or run npm run dev -- --port 3001 |
What you learned
You built and deployed a working weather dashboard. You can now:
- create a [Product name] project and run it locally,
- read user input from a form and pass it in the URL,
- call an external API with a secret key kept out of your code,
- show a friendly message when something goes wrong,
- deploy an app and share its link.
Next steps
- Next tutorial: [Add a five-day forecast with charts].
- How-to guide: [How to cache API responses].
- Reference: [Configuration options for deploy].
- Explanation: [How server rendering works in Product name].
Standard and licence note
The structure of this template is adapted from the Diátaxis framework by Daniele Procida (https://diataxis.fr), licensed under CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0/). The template text is original; the adapted structure is shared under CC BY-SA 4.0.
Related templates
Blog Post Template
Long-form blog post: search metadata, hook, body, mistakes and reader questions, sources, byline and dates, disclosure, pre-publish checklist
Writing & ContentBook Chapter Template
Book chapter: outline (opening, turn, close), scene list, draft, word-count tracker, continuity notes, revision checklist
Writing & ContentNonfiction Book Proposal Template
Nonfiction book proposal: hook, author platform, audience, comparable titles, marketing plan, chapter outline, sample chapter, specs