Skip to content
Docs · Start here

Quickstart: your first app

From signup to a live app with a database, browser uploads to storage and a payment link, on the free Hobby plan, with code that runs as written: an edge program that starts as one worker.js, no server to run.

View as Markdown
All topics
On this page

You will build a small notes app that stores notes in an edge SQLite database, lets the browser upload attachments straight to object storage, and sells an upgrade through a hosted checkout. The app is an edge program: worker.js serves the page and its API from the edge at https://<slug>.harakumo.app, with nothing to keep awake. It starts as one file; as it grows, split it into modules that worker.js imports (When the app grows: modules, below).

Every step works on the free Hobby plan. An app that needs a long-running Node.js server (Express, Next.js with a server) deploys the same way as a server app, which is on every plan (one per person on Hobby); a free one sleeps after 5 idle minutes.

Replace the values in angle brackets with the ones each step prints.

Or launch one in a minute

To skip the steps, launch: one call makes the project, its database, sign-in and the app's own key, creates its tables and puts a first version live in about a minute, as one edge program made for its kind (a store, a booking site, a SaaS …). The steps below build the same kind of app by hand. Launching needs a verified email (step 1).

CLI 0.5.0 or later
harakumo launch "An online flower shop called Bloom"
# ✓ Project, Services, Database tables, Deploy, Live, each with its time
# ✓ Bloom #<projectId> is live at https://bloom.harakumo.app
SDK 0.5.0 or later
const { url, launch } = await hk.launch({ description: 'An online flower shop called Bloom' });
// launch.ok, launch.steps: [{ key, label, ms, ok }]
curl
curl -X POST https://harakumo.com/api/launch \
  -H "Authorization: Bearer $HARAKUMO_API_KEY" -H "content-type: application/json" \
  -d '{ "description": "An online flower shop called Bloom" }'

Projects (Launch an app) has the whole request and answer. Your AI does the same with launch_app.

1. Sign up and create a setup key

  1. Sign up at harakumo.com/signup and verify your email: press the button in the email we send, or give its 6-digit code to your AI connector (verify_email). Verify now: deploys, functions, sending email, domains and live payment links wait for it. Codes work for 24 hours, and the first verification adds a welcome AI credit to your balance while the offer lasts.
  2. Open the Connect page (/dashboard/connect) and make a key for the whole workspace, with full access (an owner or admin makes it; signing up makes you the owner). It stays on your machine for setup.
Terminal
npm install -g @harakumo/cli
export HARAKUMO_API_KEY=hk_live_…          # the key you just created
harakumo login --key $HARAKUMO_API_KEY

2. Create the project, a database, a bucket and a payment account

Terminal
harakumo projects create notes-app       # ✓ Created project notes-app #<projectId>
harakumo db create <projectId> notes     # ✓ Creating notes (sqlite, #<dbId>)
harakumo db query <dbId> "CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT NOT NULL, attachment TEXT, created_at TEXT DEFAULT CURRENT_TIMESTAMP)"
harakumo storage create <projectId> uploads
harakumo storage <projectId>             # lists buckets with their ids: note <bucketId>

# Payments are live as soon as they are enabled:
curl -X POST https://harakumo.com/api/projects/<projectId>/payments \
  -H "Authorization: Bearer $HARAKUMO_API_KEY"
# → { "account": { "id": <accountId>, … } }

3. The app's key and settings

Your setup key can do anything in the workspace, so it never goes in the app: there it would reach every project in the workspace. The app gets its own key automatically, HARAKUMO_API_KEY, set at every deploy and never shown: it works for every service in this project, AI and email included, and nothing outside it.

Every deploy also gives the app the ids of its database and bucket, under the names the Build Standard uses, when the project has one of each. Only the payment account id is yours to set, in the dashboard (project → Environment) or from the terminal:

VariableValue
HARAKUMO_API_KEYset for the app at every deploy: nothing to do
HARAKUMO_DATABASE_IDset at every deploy: <dbId>, the project's one database
HARAKUMO_BUCKET_IDset at every deploy: <bucketId>, the project's one bucket
PAYMENTS_ACCOUNT_ID<accountId>: set it yourself
Terminal
harakumo env set <projectId> PAYMENTS_ACCOUNT_ID=<accountId>
One variable with curl
curl -X POST https://harakumo.com/api/projects/<projectId>/env \
  -H "Authorization: Bearer $HARAKUMO_API_KEY" -H "content-type: application/json" \
  -d '{"key":"PAYMENTS_ACCOUNT_ID","value":"<accountId>"}'
# → 201 { "changed": { "key": "PAYMENTS_ACCOUNT_ID", "target": "production", "value_length": … }, … }: names and lengths, never values

Environment variables are copied into the app when it deploys. After changing one, redeploy. To run the app on your laptop, harakumo env pull <projectId> (CLI 0.5.0 or later) writes the settings your key may read to .env.local; the app's own key stays on Harakumo, so set a key limited to this project there yourself (the Connect page makes one).

4. Write the app

Start with one file in a folder called notes-app. A worker.js at the root deploys as an edge program: it answers every request to the app, reads the project's environment variables as env.NAME, and calls the Harakumo API with plain fetch. Nothing is installed and nothing is built: the files you upload run as they are.

worker.js
// The whole notes app: the page and its API, on the edge.
const API = 'https://harakumo.com/api';

// One call to the Harakumo API with the app's own key (step 3).
async function hk(env, path, body) {
  const res = await fetch(API + path, {
    method: body === undefined ? 'GET' : 'POST',
    headers: { authorization: 'Bearer ' + env.HARAKUMO_API_KEY, 'content-type': 'application/json' },
    body: body === undefined ? undefined : JSON.stringify(body),
  });
  const data = await res.json();
  if (!res.ok) throw new Error(data.error || 'Harakumo answered ' + res.status);
  return data;
}

const json = (data, status = 200) => Response.json(data, { status });

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    const route = request.method + ' ' + url.pathname;
    try {
      if (route === 'GET /') {
        return new Response(PAGE, { headers: { 'content-type': 'text/html; charset=utf-8' } });
      }

      // Notes live in the edge SQLite database; every query is one HTTPS call.
      if (route === 'GET /api/notes') {
        const { results } = await hk(env, '/databases/' + env.HARAKUMO_DATABASE_ID, {
          sql: 'SELECT id, body, attachment, created_at FROM notes ORDER BY id DESC LIMIT 50',
        });
        return json(results);
      }
      if (route === 'POST /api/notes') {
        const { body, attachment = null } = await request.json();
        await hk(env, '/databases/' + env.HARAKUMO_DATABASE_ID, {
          sql: 'INSERT INTO notes (body, attachment) VALUES (?, ?)',
          params: [String(body), attachment],
        });
        return json({ ok: true }, 201);
      }

      // The browser uploads straight to storage with a signed URL; the bytes never pass through here.
      // size locks the link to the file's exact length, so nobody holding it can send more; it lasts at most 15 minutes.
      if (route === 'POST /api/upload-url') {
        const { filename, contentType, size } = await request.json();
        const key = 'attachments/' + Date.now() + '-' + String(filename).replace(/[^a-zA-Z0-9._-]/g, '_');
        const signed = await hk(env, '/storage/' + env.HARAKUMO_BUCKET_ID, { key, method: 'put', contentType, size });
        return json({ url: signed.url, key });
      }

      // A hosted checkout. The buyer comes back to /thanks?session_id=…
      if (route === 'POST /api/checkout') {
        const checkout = await hk(env, '/payments/' + env.PAYMENTS_ACCOUNT_ID, {
          amountCents: 500,
          description: 'Notes Pro',
          successUrl: url.origin + '/thanks',
          cancelUrl: url.origin + '/',
        });
        return json({ url: checkout.url });
      }

      // Confirm the payment here; never trust the redirect alone.
      if (route === 'GET /thanks') {
        const { paid, payment } = await hk(env, '/payments/' + env.PAYMENTS_ACCOUNT_ID + '/sessions/'
          + encodeURIComponent(url.searchParams.get('session_id') || ''));
        return new Response(paid
          ? 'Paid $' + (payment.amount_cents / 100).toFixed(2) + ', thank you!'
          : 'Payment not completed yet.');
      }

      return new Response('Not found', { status: 404 });
    } catch (err) {
      return json({ error: err.message }, 502);
    }
  },
};

// The page: a tab icon and a phone layout from the start.
const PAGE = `<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Notes</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%234F46E5'/%3E%3Ctext x='32' y='44' font-family='system-ui' font-size='36' font-weight='700' fill='white' text-anchor='middle'%3EN%3C/text%3E%3C/svg%3E">
<style>body { font: 16px/1.5 system-ui, sans-serif; max-width: 560px; margin: 40px auto; padding: 0 16px; }</style>
<form id="note"><input name="body" placeholder="Write a note" required> <input type="file" name="file"> <button>Save</button></form>
<ul id="list"></ul>
<button id="buy">Upgrade for $5</button>
<script type="module">
const json = (url, body) => fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).then(r => r.json());

async function load() {
  const notes = await (await fetch('/api/notes')).json();
  document.getElementById('list').replaceChildren(...notes.map(n => {
    const li = document.createElement('li');
    li.textContent = n.body + (n.attachment ? ' (attachment)' : '');
    return li;
  }));
}

document.getElementById('note').onsubmit = async (e) => {
  e.preventDefault();
  const form = new FormData(e.target);
  const file = form.get('file');
  let attachment = null;
  if (file && file.size) {
    const type = file.type || 'application/octet-stream';
    const { url, key } = await json('/api/upload-url', { filename: file.name, contentType: type, size: file.size });
    await fetch(url, { method: 'PUT', headers: { 'content-type': type }, body: file });  // same Content-Type as signed
    attachment = key;
  }
  await json('/api/notes', { body: form.get('body'), attachment });
  e.target.reset();
  load();
};

document.getElementById('buy').onclick = async () => {
  location.href = (await json('/api/checkout', {})).url;
};
load();
</script>
`;

5. Deploy

Terminal
harakumo deploy <projectId> ./notes-app    # uploads the folder
harakumo deploys <projectId>               # queued → deploying → ready, in seconds

Keep secrets in environment variables, never in the file. After changing a variable, deploy again: an edge program reads them when it deploys.

What happens

The pipeline finds worker.js at the root and deploys it as an edge program at https://<slug>.harakumo.app, with the project's production environment variables. Nothing builds and nothing sleeps: it answers from the edge location nearest each visitor. When the status is ready, open the address.

  • Notes are saved through the database API, so they survive every deploy.
  • Attachments go from the browser straight to the bucket with a signed link.
  • Need a full Node.js server instead (Express, Next.js)? The same deploy runs it as a server app, which is on every plan (one per person on Hobby).

6. Take a payment

Press Upgrade on the live app. The hosted checkout charges a real card: to try the flow, pay yourself and refund it from the project's Payments page in the dashboard (refunds are for the workspace owner). You return to /thanks?session_id=…, and the app confirms the payment with the session lookup.

The payment appears on the project's Payments page in the dashboard as Earnings: $5.00 less the 3.9% + 30¢ fee. Each payment is held 7 days before the workspace owner can withdraw it.

When the app grows: modules

An edge program is worker.js (or _worker.js) at the root plus the .js and .mjs files it imports by relative path (import { route } from './lib/route.js', export * from '../shared/util.mjs', await import('./pages/home.js')), followed file to file. Each is uploaded as a module under its path next to worker.js, by the same harakumo deploy. Files nothing imports (public/app.js) are not part of the program.

Imports name the file in full, extension included. Nothing is installed or bundled: import no npm packages unless you bundle them into worker.js first. Node.js built-ins are imported with the node: prefix (node:crypto), and the program then runs with the Node.js compatibility layer. At most 200 modules and 10 MB in all, worker.js included.

Upload the modules as you wrote them rather than one bundle: every upload is saved in the project's repo, which then shows the code itself (see Repos: project memory). A program that needs npm packages is bundled into worker.js; push its source to the repo with keep: true, and later bundled uploads keep it.

The deploy log saysWhat to change
worker.js imports 1 module, uploaded with it: lib/notes.jsNothing: the program went up with its modules.
worker.js imports './lib/notes', and lib/notes is not in the upload. lib/notes.js is: imports name the file in full, so write './lib/notes.js'.Add the extension to the import.
worker.js imports './lib/notes.js', and lib/notes.js is not in the upload. Upload it with the rest of the program, or fix the path.Upload the file, or correct the path.
worker.js imports 'hono', an npm package. Edge programs run the files you upload as they are: bundle the program into worker.js first, or copy the code you need into your own modules.Bundle the program into worker.js, or write that code in a module of your own. A Node.js built-in named without its prefix (crypto) gets one more sentence: import node:crypto.
worker.js imports './page.css': an edge program is made of .js and .mjs modules, and page.css is not one. Bundle the program into worker.js first, or make page.css a .js module.Keep the text in a .js module (export const CSS = …).
worker.js imports '/lib/x.js'. Modules import each other by relative path, starting with ./ or ../.Start the path with ./ or ../.
This edge program (worker.js and the files it imports) is more than 200 modules, the most one program may be. Bundle it into fewer files first.Bundle it into fewer files.
worker.js, split into modules
// Step 4's app, split up: lib/page.js is `export const PAGE = …` and lib/hk.js is
// `export async function hk(…)`, moved as they are. The upload, checkout and thanks
// routes move into modules the same way.
import { listNotes, addNote } from './lib/notes.js';
import { PAGE } from './lib/page.js';

export default {
  async fetch(request, env) {
    const route = request.method + ' ' + new URL(request.url).pathname;
    if (route === 'GET /') return new Response(PAGE, { headers: { 'content-type': 'text/html; charset=utf-8' } });
    if (route === 'GET /api/notes') return Response.json(await listNotes(env));
    if (route === 'POST /api/notes') return Response.json(await addNote(env, await request.json()), { status: 201 });
    return new Response('Not found', { status: 404 });
  },
};
lib/notes.js
import { hk } from './hk.js';   // the hk() helper from step 4, in a module of its own

export async function listNotes(env) {
  const { results } = await hk(env, '/databases/' + env.HARAKUMO_DATABASE_ID, {
    sql: 'SELECT id, body, attachment, created_at FROM notes ORDER BY id DESC LIMIT 50',
  });
  return results;
}

export async function addNote(env, { body, attachment = null }) {
  await hk(env, '/databases/' + env.HARAKUMO_DATABASE_ID, {
    sql: 'INSERT INTO notes (body, attachment) VALUES (?, ?)',
    params: [String(body), attachment],
  });
  return { ok: true };
}

A refusal fails the deployment before anything is sent, and what was live keeps serving. The same problem in a dynamic import() is only a warning in the log: the deploy goes ahead, and that code fails when it runs.

Building with an AI assistant

An AI assistant can build this for you. With the AI connector it calls Harakumo's tools by name, and get_build_standard tells it what a finished app includes (see Build standard).

An AI that has an API key and no connector calls the same tools at POST https://harakumo.com/mcp: one JSON-RPC tools/call per request, the key in the Authorization header, and an Accept header that lists both application/json and text/event-stream. The answer is one data: line holding the JSON-RPC result. tools/list lists the tools the key may use.

One tool call with a key
curl -s https://harakumo.com/mcp \
  -H "Authorization: Bearer $HARAKUMO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"whoami","arguments":{}}}'

Next

  • Databases — batch statements, export, limits and errors.
  • Storage — download links, listings and folders.
  • Payments — webhooks, metadata and refunds.
  • Auth pools — add sign-in for your users.
  • Limits & scaling — what this app can handle, and where the walls are.