Deploy a Function

Write TypeScript and deploy it from the dashboard. Every deploy creates a new versioned snapshot. The active version is what gets executed.

Function structure

Every function must export a handler function that accepts ctx and returns a value:

index.tsTypeScript
export async function handler(ctx) {
  // ctx.request — incoming request body and headers
  // ctx.db.insert(collection, data)
  // ctx.db.find(collection, filters)
  // ctx.db.update(id, data)
  // ctx.db.delete(id)
  // Deno.env.get('SECRET_NAME') — encrypted secrets

  return { ok: true }
}

A real example

A function that sends a welcome email when called:

send-welcome-email/index.tsTypeScript
export async function handler(ctx) {
  const { userId } = ctx.request;

  // Read the user from the database
  const users = await ctx.db.find('users', { id: userId });
  if (!users.length) {
    return { error: 'User not found' };
  }

  const user = users[0];
  const apiKey = Deno.env.get('SENDGRID_KEY');

  // Call external email API
  const res = await fetch('https://api.sendgrid.com/v3/mail/send', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: [{ email: user.data.email }],
      from: { email: 'hello@myapp.com' },
      subject: 'Welcome to MyApp!',
      text: `Hi ${user.data.name}, welcome aboard!`,
    }),
  });

  return { sent: res.ok, email: user.data.email };
}

Deploying from the dashboard

1

Navigate to your project → Functions

2

Click Deploy in the top right of the functions panel

3

Enter a function name (e.g. send-welcome-email)

4

Select a timeout — 5s (standard), 10s (extended), or 30s (long-running)

5

Write or paste your TypeScript code in the editor

6

Click Deploy — your function is live immediately

Versioning

Every deploy creates a new version (v1, v2, v3...). The latest version is automatically set as active. DB triggers always execute the currently active version — so redeploying a function upgrades all triggers pointing to that function name automatically.

Version-agnostic triggers

Triggers are bound to a function name, not a version. When you redeploy, all triggers on that function name automatically use the new active version. You never need to update trigger configuration after a redeploy.

Function naming

Lowercase letters, numbers, and hyphens only
Maximum 64 characters
Must be unique within your project
Examples: send-welcome-email, sync-user-profile, process-payment