Skip to content

DevServer

Source: src/Build/DevServer.ts

A long-lived shell process scoped to a stack instance, started during alchemy dev and restarted when inputs change. During deploy this is a no-op — DevServer resources only run in dev mode.

The child process runs inside the dev sidecar so it survives user-code HMR restarts. Its stdout/stderr are mirrored to the terminal and scanned for the first http(s)://… URL, which is exposed as the url output attribute.

Pass a shell command that starts a long-lived dev server. Alchemy runs it in the background and extracts the first URL it prints.

const dev = yield* DevServer("Frontend", {
command: "npm run dev",
});
console.log(dev.url); // e.g. "http://localhost:5173"

Use cwd to run the command in a subdirectory — useful in monorepos where each package has its own dev server.

const dev = yield* DevServer("Web", {
command: "npm run dev",
cwd: "apps/web",
});

Extra environment variables are merged on top of process.env. Sensitive values can be wrapped in Redacted to keep them out of logs and state files.

const dev = yield* DevServer("Api", {
command: "npm run dev",
env: {
PORT: "4000",
DATABASE_URL: Redacted.make("postgres://..."),
},
});