Add Runlane to your app
Connect tasks, triggers, and workers through one shared runtime.
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.
Use this guide to add Runlane to an existing TypeScript app. The example uses three files so each part has one owner:
src/
├── tasks/send-welcome-email.ts # task definition and handler
├── runlane.ts # lane, queues, and task catalog
└── users/queue-welcome-email.ts # application triggerThe example assumes Node.js 22.18.0 or newer, the packages from the local quickstart, and an email HTTP endpoint configured through EMAIL_API_URL and EMAIL_API_TOKEN.
Set TypeScript's moduleResolution to node16, nodenext, or bundler. Runlane packages use subpath exports such as @runlane/observability/opentelemetry, which the legacy node10 setting cannot resolve.
Define the task beside its domain code
Create src/tasks/send-welcome-email.ts. Export the task directly so the runtime can register it:
import { task } from '@runlane/core'
import * as z from 'zod'
const env = z
.object({
EMAIL_API_TOKEN: z.string().min(1),
EMAIL_API_URL: z.url(),
})
.parse(process.env)
export const sendWelcomeEmail = task({
id: 'email.send-welcome',
schema: z.object({ email: z.email() }),
async run({ email }, context) {
const response = await fetch(env.EMAIL_API_URL, {
body: JSON.stringify({ template: 'welcome', to: email }),
headers: { authorization: `Bearer ${env.EMAIL_API_TOKEN}`, 'content-type': 'application/json' },
method: 'POST',
signal: context.signal,
})
if (!response.ok) throw new Error(`Email API returned ${response.status}`)
},
})The handler validates configuration, calls the email API, passes context.signal, and turns a non-success response into a visible task failure. A retry can call the email API again. To send at most once, put the call in a step and pass its token as an idempotency key; see make side effects safe to repeat.
The task schema validates data before it enters durable execution.
Create one shared runtime
Create src/runlane.ts. This is the shared runtime module:
import { createRunlane, RunRetention, queue } from '@runlane/core'
import { createLocalLane, createTestLane } from '@runlane/lane-local'
import { sendWelcomeEmail } from './tasks/send-welcome-email.js'
const defaultQueue = queue({ name: 'default', default: true })
export const runlane = createRunlane({
retention: {
succeeded: RunRetention.deleteAfter('7d'),
cancelled: RunRetention.deleteAfter('7d'),
failed: RunRetention.deleteAfter('30d'),
expired: RunRetention.deleteAfter('7d'),
},
lane: process.env.NODE_ENV === 'test' ? createTestLane() : createLocalLane(),
queues: [defaultQueue],
tasks: { sendWelcomeEmail },
})The exported runlane instance registers the lane, queues, and task catalog in one place. Set NODE_ENV=test in your test runner to select createTestLane(). Without this switch, app tests fail in CI because runlane dev is not running.
Import this instance wherever the app triggers work. Do not construct a runtime inside a request handler. In development, all app processes and module copies connect to dev's store. In tests, same-name test lanes share runs and wake signals within one process.
Trigger from application code
Create src/users/queue-welcome-email.ts beside the application code that decides when a welcome email is needed:
import { runlane } from '../runlane.js'
export async function queueWelcomeEmail(user: { readonly email: string }) {
const { run } = await runlane.trigger(runlane.tasks.sendWelcomeEmail, {
email: user.email,
})
return run.id
}Use the task handle exposed by the runtime catalog. You do not need to pass the runtime through another wrapper.
Store or return run.id when the caller needs to inspect the work later. Triggering accepts the work; it does not wait for the task handler to finish.
Run the app and worker
Create runlane.config.ts in the project root:
import { type RunlaneCliConfig } from '@runlane/cli'
import { runlane } from './src/runlane.js'
export default { runtime: () => runlane } satisfies RunlaneCliConfigInstall @runlane/cli as a development dependency. Start the worker and maintenance in terminal one:
npx runlane devStart your app in terminal two with its usual development command. Both use the same runtime module and lane name. App triggers reach the dev worker without changing application code when you switch lanes.
The local lane discovers dev on first storage use. It searches upward from the working directory for the nearest default runlane.config.*. Run the app from that project or a child directory. A CLI --config <path> uses that exact file as its project key; app processes must discover that same default file. For a project without a default config, keep the same working directory and use the default config path. See local discovery.
The app can start before dev, but storage operations fail until dev is ready. Start dev and retry the operation. Lane creation and module import start no worker and perform no file or network I/O. Use createTestLane() with drain() or executeNext() for tests that control execution.
If dev stops, existing remote lanes fail with storage_unavailable and tell you to restart dev. After dev restarts, later operations reconnect to its fresh, empty store. Old runs are gone. Call await runlane.close() during app shutdown to release connections and lane handles.
The local lane is for Node.js development. In production, use a Postgres or Redis lane. Serverless Node.js functions can trigger work. The SQS lanes run workers on AWS Lambda, and HTTP push runs them in your own route. See where Runlane runs.
Check the integration
Create a test that triggers the registered task and waits for the stored outcome or email request. For a test that controls execution with drain(), create a runtime with createTestLane({ name: 'email-test' }). See test tasks.
For production, choose a durable lane. The dev bridge does not persist runs.
Use the application API reference to look up task and runtime options, return values, defaults, and error handling.
To show run progress in a browser, see set up realtime.