Skip to content
Luna
Esc
↑↓navigate↵open⌘Jpreview
On this page

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 dev running the List luna 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=module

Write 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.ts

See 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

Was this page helpful?