Docs / Build / Functions

Functions

A function is a small piece of backend code that runs when it is called. Use one for things that should not live in the browser: sending an email, calling a paid API with a secret key, validating a purchase.

Functions are in beta.

Write one

Functions → New function, or ask the AI Engineer.

export default async function handler(event) {
  // event.body — what the caller sent
  // event.user — the signed-in FASTBASE Auth user, or null
  if (!event.user) throw new Error("Sign in first")

  const response = await fetch("https://api.example.com/send", {
    method: "POST",
    headers: { authorization: `Bearer ${process.env.MAIL_API_KEY}` },
    body: JSON.stringify({ to: event.user.email, template: "welcome" }),
  })
  return { sent: response.ok }
}

The file is an ES module with a default export. Whatever it returns must be JSON-serialisable.

Call it

const result = await fastbase.functions.invoke("send-welcome", { plan: "pro" })

Functions can be called with the public key, so check event.user yourself when a function should not be open to everyone.

Environment

A function receives the project’s production environment variables — including DATABASE_URL and anything you added under Environment — and nothing from FASTBASE itself.

Limits

Time 10 seconds per call
Memory 128 MB
Output 64 KB of logs are kept
Packages Node.js built-ins and fetch only — no npm install yet

Isolation

Each call runs in a fresh Node.js process under the Node permission model: no access to the file system outside its own temporary folder, no child processes, no worker threads. Secret values a function prints are masked in its stored logs.

This is process-level isolation. It is appropriate for your own code; it is not yet the container or microVM sandbox required to run untrusted third-party code, which is on the roadmap.