Skip to Content
Runlane
Get started

Run your first task

Start local development, trigger one task, and read its stored result.

With createLocalLane(), runlane dev owns the runs in its memory. The app, CLI, and worker reach that store over a loopback bridge: a token-protected connection that only accepts traffic from your own machine (127.0.0.1). The app never keeps runs in its own memory. Without dev, the first trigger or read fails with storage_unavailable. Start dev and retry; no app restart is needed.

In this tutorial, you will define a task, trigger it from the CLI, and read its result. Use two terminals: one keeps the dev store and worker running, and the other sends commands to it.

Before you start

You need Node.js 22.18.0 or newer and an existing TypeScript project.

Install Runlane, the local lane, and Zod:

npm install @runlane/core @runlane/lane-local zod

Install the CLI as a development dependency:

npm install --save-dev @runlane/cli

Check Node:

node --version

Create the task and runtime

Create runlane-quickstart.mts. The .mts extension makes it an ES module regardless of your project's module setting:

runlane-quickstart.mts
import { createRunlane, RunRetention, queue, task } from '@runlane/core'
import { createLocalLane } from '@runlane/lane-local'
import * as z from 'zod'

const sendWelcomeEmail = task({
  id: 'email.send-welcome',
  output: z.object({ sentTo: z.string() }),
  schema: z.object({ email: z.email() }),
  run: ({ email }) => ({ sentTo: email }),
})

export const runlane = createRunlane({
  retention: {
    succeeded: RunRetention.deleteAfter('7d'),
    cancelled: RunRetention.deleteAfter('7d'),
    failed: RunRetention.deleteAfter('30d'),
    expired: RunRetention.deleteAfter('7d'),
  },
  lane: createLocalLane(),
  queues: [queue({ name: 'default', default: true })],
  tasks: { sendWelcomeEmail },
})

The input schema validates each payload before Runlane creates a run. The output schema validates the result before success. The named catalog keeps these types tied to the registered task.

Create the CLI config in the same directory:

runlane.config.mts
import { type RunlaneCliConfig } from '@runlane/cli'

import { runlane } from './runlane-quickstart.mjs'

export default { runtime: () => runlane } satisfies RunlaneCliConfig

The CLI's TypeScript loader resolves the .mjs import to the .mts source. You do not need a build step.

Start dev in terminal one

From your project directory:

npx runlane dev

Wait for dev started and leave it running. This process holds the runs and starts the worker and maintenance.

Trigger and read in terminal two

From the same directory:

npx runlane trigger email.send-welcome '{"email":"ada@example.com"}'

Copy the printed run ID. Replace <run-id> in these commands:

npx runlane runs logs <run-id> --follow
npx runlane runs get <run-id> --json

The follow command waits for a final status. The stored run should contain:

{ "status": "succeeded", "output": { "sentTo": "ada@example.com" } }

The JSON response also includes the run ID and other saved fields. The trigger stored queued work in dev's memory. Its worker claimed the run and saved the result. The second terminal read that same store.

If it does not work

For storage_unavailable, start runlane dev for the same config path and retry. If dev is starting or stopping, wait for it to finish, then retry. No run was accepted by a trigger that failed because dev was absent.

For an unsupported engine error, upgrade Node to 22.18.0 or newer. For an unknown task, check the runtime's tasks catalog and the task ID in the trigger command.

Stop dev with Ctrl+C when finished. Stopping dev deletes local runs. Use createTestLane() with drain() in tests, and a Postgres or Redis lane for runs that must survive restarts.

Next, add Runlane to your app without duplicating runtime configuration.

On this page