Markdown Editor

Tutorial Template (Diátaxis)

Diátaxis tutorial – learning goals, prerequisites, numbered lessons with visible results, checkpoints, troubleshooting

Writing & ContentStandardDiátaxisCC BY-SA 4.0tutorial

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.

FieldValue
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 testedYYYY-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 see v22 or 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

  1. Open a terminal and create the project from the starter template:

    npx create-[product]-app weather-dashboard
    

    You should see Success! Created weather-dashboard after about a minute.

  2. Move into the new folder and start the development server:

    cd weather-dashboard
    npm run dev
    

    The terminal shows Local: http://localhost:3000.

  3. Open http://localhost:3000 in 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

  1. Open src/page.tsx in 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>
      );
    }
    
  2. Save the file.

    The browser reloads and shows the heading Weather, a text box and a Search button.

  3. Type Lisbon and 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

  1. In your [Product name] dashboard, go to API keys, select Create key, and copy the key.

  2. Create a file named .env.local in the project folder with this line, pasting your key after the equals sign:

    WEATHER_API_KEY=[your-key]
    
  3. Stop the server with Ctrl+C and start it again with npm run dev, so that it reads the new file.

  4. Replace src/page.tsx with 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>
      );
    }
    
  5. Save the file, type Lisbon and 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

  1. Search for Xyzzyville, a city that does not exist.

    The page shows an error screen. This is what users would see today.

  2. In src/page.tsx, change the line that calls getWeather to 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>}
    
  3. Save and search for Xyzzyville again.

    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

  1. Stop the server and run:

    npx [product] deploy
    
  2. When asked, add WEATHER_API_KEY as a secret and paste your key.

    After about a minute the terminal prints a URL such as https://weather-dashboard-ab12.example.app.

  3. Open the URL on your phone and search for your own city.

Checkpoint: Your dashboard is live on the internet.

Troubleshooting

What you seeLikely causeWhat to do
command not found: npxNode.js is not installed or not on the pathInstall Node.js 22 and open a new terminal
Page still shows Welcome after Lesson 2File saved in the wrong folderCheck the path is weather-dashboard/src/page.tsx
Request failed: 401API key missing or not loadedCheck .env.local, then restart the server (Lesson 3, step 3)
Port 3000 is already in useAnother server is runningStop 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