# Build your first app

> Build a small Node.js app that lists your restaurants and their details, end to end.

Source: https://docs.gastrogate.io/docs/tutorials/first-app

In this tutorial you will build a command-line app that lists the restaurants your API key can access. Along the way you'll learn how to structure queries, use variables and paginate.

> [!NOTE]
> You need Node.js 20+ and an API key. If you don't have a key yet, follow the [Quickstart](https://docs.gastrogate.io/docs/getting-started/quickstart.md) first.

## Set up the project

```bash
mkdir loco-restaurants && cd loco-restaurants
npm init -y
```

## Write a tiny client

Create `loco.mjs`:

```javascript
export async function loco(query, variables = {}) {
  const res = await fetch("https://api.thelocoapp.com/graphql", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.LOCO_API_KEY}`,
    },
    body: JSON.stringify({ query, variables }),
  });
  const body = await res.json();
  if (body.errors?.length) throw new Error(body.errors.map((e) => e.message).join("\n"));
  return body.data;
}
```

## List every restaurant

Create `index.mjs`:

```javascript
import { loco } from "./loco.mjs";

const QUERY = `query Restaurants($after: String) {
  restaurants(first: 50, after: $after) {
    edges { node { id } }
    pageInfo { hasNextPage endCursor }
  }
}`;

let after = null;
do {
  const { restaurants } = await loco(QUERY, { after });
  for (const { node } of restaurants.edges) console.log(node.id);
  after = restaurants.pageInfo.hasNextPage ? restaurants.pageInfo.endCursor : null;
} while (after);
```

Run it:

```bash
LOCO_API_KEY=... node index.mjs
```

## What you learned

- The API is one endpoint; the query decides what you get back.
- Lists are paginated with cursors — see [Pagination](https://docs.gastrogate.io/docs/concepts/pagination.md).
- Explore more fields on [`Restaurant`](https://docs.gastrogate.io/docs/api/types/Restaurant.md) and add them to your query.
