TypeScript quickstart
Add an item to a list and read the list back from a TypeScript program with the Luna client.
At the end of this page you have a TypeScript program that adds an item to a List luna and reads the list back. It uses createClient from luna/client and runs with Node.js.
Prerequisites
- The Quickstart done, with
luna devrunning theListluna and its URL and key in.env.local. - Node.js 22.18 or later.
Install the SDK
npm install --install-links "$(luna sdk ts --path)"Use ES modules
npm pkg set type=moduleWrite the program
Add an app folder beside the luna folder.
- .env.local
- package.json
- app/
- main.ts
- luna/
- luna.config.ts
- lunas/
- list.ts
import { createClient } from "luna/client";
import type { List } from "../luna/lunas/list.ts";
const client = createClient({ url: process.env.LUNA_URL!, key: process.env.LUNA_KEY });
const list = client.luna<typeof List>("List", "weekend");
await list.mutate("add", { text: "bread" });
const items = await list.read("all");
for (const item of items) console.log(item.text);
client.close();Run it
node --env-file=.env.local app/main.tsSee the result
The program adds bread to the list named weekend, then prints each item of that list.
bread
Run it again and the list holds two items. The type import of List checks each handler name and argument, and Node.js drops it when it runs the file.
Next steps
- Call lunas from TypeScript covers every call, the client’s options and its errors.
- Use Luna with React shows the same list in a component that updates by itself.
- Subscribe to a query follows the list as other people change it.