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:
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:
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
Navigate to your project → Functions
Click Deploy in the top right of the functions panel
Enter a function name (e.g. send-welcome-email)
Select a timeout — 5s (standard), 10s (extended), or 30s (long-running)
Write or paste your TypeScript code in the editor
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.