Skip to Content

Functions

Run one TypeScript file on Bun, with no build. Serve it on a URL, or run it on a schedule.

A function is a service made of a single TypeScript file. StackBlaze runs it on Bun with no build step. Without a schedule it serves HTTP on its own URL. With a schedule it runs as a job instead.

Add a function

In your project, click + Service and choose Function (One TypeScript file, no build).

The Add to Dev menu with Function: One TypeScript file, no build
The Add to Dev menu with Function: One TypeScript file, no build

It is created and deployed right away

There is nothing to fill in and nothing to commit. The function is created under the name function (then function-2, and so on), deployed at once, and its panel opens on the Code tab. The header shows its URL and TypeScript on Bun.

The Code tab has the function's URL with Copy, an editor with the file, and Deploy. A new function starts from this file:

// Runs on Bun. Import any npm package: import { Hono } from "hono@4"
Bun.serve({
  port: Number(process.env.PORT ?? 8080),
  fetch(req) {
    return new Response("Hello from your function");
  },
});
A new function: the Code tab with its URL, Copy, the starter file and Deploy
A new function: the Code tab with its URL, Copy, the starter file and Deploy

Opening the URL returns Hello from your function.

Change the code and deploy

Edit the file. Unsaved changes appears next to Deploy. Click Deploy: a Deployed notice confirms it. The new code answers on the same URL once the update has rolled out (about half a minute when we tried it).

The Code tab with edited code and Unsaved changes
The Code tab with edited code and Unsaved changes
After Deploy: the Deployed notice
After Deploy: the Deployed notice

The file can be up to 96 KB.

Variables

A function reads environment variables like any app, through process.env. Variables already has PORT, which the starter code listens on. To add your own, click Add variable, type a KEY and a value, then Commit 1 change → Deploy 1 change (see Environment variables).

Variables: PORT and a new GREETING variable
Variables: PORT and a new GREETING variable

With GREETING set to hello from a variable, a function that returns process.env.GREETING answered {"path":"/hello","greeting":"hello from a variable"}. Changing a variable keeps the function's code.

Run on a schedule

Settings → Schedule decides how the function runs. "With a schedule the function runs as a job on that schedule and has no URL."

Schedule: No schedule, Every 5 minutes, Every hour, Every day, Every week, Custom
Schedule: No schedule, Every 5 minutes, Every hour, Every day, Every week, Custom
  • No schedule (the default): the function serves HTTP on its URL.
  • Every 5 minutes, Every hour.
  • Every day: pick a time, in UTC (02:00 by default).
  • Every week: pick a day and a time, in UTC (Monday, 02:00 by default).
  • Custom: type a cron expression with five fields, in UTC. It starts from the expression of the option you had picked, for example 0 2 * * 1 after Every week.
Every day, with a time in UTC
Every day, with a time in UTC
Every week: Monday, 02:00 AM, UTC
Every week: Monday, 02:00 AM, UTC
Custom, with a cron expression
Custom, with a cron expression

Changing the schedule is a staged change: Commit 1 change, then Deploy 1 change. Once a schedule is set, the URL stops answering.

Each run executes the file once with bun run. With the starter's Bun.serve code, the runs printed nothing. A scheduled function should do its work, print what it needs to, and exit. For example:

console.log(`Ran at ${new Date().toISOString()}: ${process.env.GREETING ?? "hello"}`);
The Code tab with a short file that logs one line
The Code tab with a short file that logs one line

Each run's output appears in Logs, tagged with the run:

Logs: Ran at 2026-11-24T12:20:01Z: hello from a variable, from a function-run job
Logs: Ran at 2026-11-24T12:20:01Z: hello from a variable, from a function-run job

To serve HTTP again, set No schedule, deploy the change, and deploy code that calls Bun.serve again.

1 change to apply: Schedule */5 * * * * removed
1 change to apply: Schedule */5 * * * * removed

From the CLI

stackblaze functions (or fn) does the same from the terminal. Every command takes -p <project> and -e <environment> (default production).

Create a function and wait until it answers:

stackblaze functions deploy hello --wait
!  No --file given: the function starts with a "Hello" example. Deploy your code with --file.
Waiting for function hello-bn2k…
OK Function hello is ready
url: https://hello-bn2k.….stackblaze.app

Without --file it starts from the same starter file as the dashboard. To deploy your own code, or to update it later, pass the file (up to 96 KB):

stackblaze functions deploy hello --file index.ts --wait

deploy both creates and updates. It also takes --port (default 8080) and:

  • --schedule '<cron>' to run on a schedule (five fields, UTC) instead of on request;
  • --no-schedule to serve on request again. Deploy code that calls Bun.serve with it, as in the dashboard.

The other commands:

CommandWhat it does
functions listEach function, how it runs (on request or on schedule with the expression) and its URL
functions get helloHow it runs, its URL, its status and the size of its code. --code prints the file.
functions invoke helloCalls the URL and prints the answer: OK Invoked hello (HTTP 200) then Hello from your function. --method (default POST), --path and --body shape the request.
functions delete helloDeletes it. Without a terminal, add -y.

invoke refuses a scheduled function, which has no URL: "Function hello runs on a schedule (*/5 * * * *) and has no URL to call." (exit code 1).

A function is also an app, so app commands work on it with -a <name>: stackblaze variables list -a hello lists its variables, and stackblaze events -a hello shows each scheduled run's job being created and completed.

Every option: stackblaze functions.

Other tabs and settings

  • Deployment lists each deploy, with what changed (Updated code, First Deploy), its status and who made it.
  • Logs streams the function's output (for a scheduled function, each run's output).
  • Metrics shows CPU, memory, response time, throughput and status codes over 2h, 24h or 7d.
  • Settings also has Custom domains (the default URL includes HTTPS) and Log retention.
Deployment: deploys with Updated code and First Deploy
Deployment: deploys with Updated code and First Deploy
Metrics: CPU, memory and HTTP charts
Metrics: CPU, memory and HTTP charts
Settings: Schedule, Custom domains and Log retention
Settings: Schedule, Custom domains and Log retention

On this page