Run a service in its runtime
Use this guide when you put a Node, Bun, Deno, Python, Rust, Go or Java service on devlanes and want the lines its code and command need.
Listen on the port and host
Section titled “Listen on the port and host”Each service gets its port in PORT and the loopback address in HOST. Read both where the server starts listening.
Node
const port = Number(process.env.PORT ?? 3000);server.listen(port, process.env.HOST ?? "127.0.0.1");Bun
Bun.serve({ port: Number(process.env.PORT ?? 3000), hostname: process.env.HOST ?? "127.0.0.1", fetch,});Deno
Deno.serve({ port: Number(Deno.env.get("PORT") ?? 8000), hostname: Deno.env.get("HOST") ?? "127.0.0.1",}, handler);The task has to allow reading the two variables:
{ "tasks": { "dev": "deno run --watch --allow-net --allow-env=PORT,HOST main.ts" } }Python
services: api: run: uv run uvicorn acme.main:app --host 127.0.0.1 --port ${{ self.port }} --reloadservicesLong-running processes of each lane, started together after infrastructure, setup and lane.start tasks. Each service gets its own port as PORT and, with hosts, HTTPS hostnames. A service that exits shows as failed and is not restarted.
services.<name>A long-running process started with the lane, such as a dev server or a worker. Each service gets its own port from the lane's block (PORT, ${{ self.port }}); devlanes stops it with the lane and never restarts it when it exits. A service needs run or run_script, directly or through extends.
services.<name>.runCommand that starts the service. A string runs with /bin/sh -c, so pipes, && and multi-line scripts work; a list is an argv run directly without a shell. It starts in the project file's directory unless cwd is set. devlanes runs it exactly as written, so it cannot be combined with preset; prefer run_script when the command is a script in a project file. Exactly one of run and run_script is required after templates are applied. In a list, an item that is one ${{ }} expression giving a number or true/false becomes its text, such as --port followed by ${{ self.port }}.
Rust
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".into());let host = std::env::var("HOST").unwrap_or_else(|_| "127.0.0.1".into());let listener = tokio::net::TcpListener::bind(format!("{host}:{port}")).await?;Go
host := cmp.Or(os.Getenv("HOST"), "127.0.0.1")port := cmp.Or(os.Getenv("PORT"), "8080")log.Fatal(http.ListenAndServe(net.JoinHostPort(host, port), mux))Java
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));String host = System.getenv().getOrDefault("HOST", "127.0.0.1");Spring Boot and Quarkus take the port from a preset instead, as Run Spring Boot and Quarkus shows.
Reload on change
Section titled “Reload on change”devlanes leaves watching files to the runtime, so use its watch mode in the command:
- Node:
node --watch, tsx watch or nodemon. - Bun:
bun --watch. - Deno:
deno run --watch, as in the task above. - Python: uvicorn’s
--reload. - Java: Quarkus dev mode (
quarkus:dev,quarkusDev), or Spring Boot DevTools, which restarts the app when your IDE or amvn compilewrites new classes. - Go: air, building into the lane’s data folder so two lanes never run one binary. On Windows, end both paths in
api.exe.
services: api: run: - air - --build.cmd - go build -o "${{ lane.data_path }}/api" ./cmd/api - --build.entrypoint - ${{ lane.data_path }}/apiservicesLong-running processes of each lane, started together after infrastructure, setup and lane.start tasks. Each service gets its own port as PORT and, with hosts, HTTPS hostnames. A service that exits shows as failed and is not restarted.
services.<name>A long-running process started with the lane, such as a dev server or a worker. Each service gets its own port from the lane's block (PORT, ${{ self.port }}); devlanes stops it with the lane and never restarts it when it exits. A service needs run or run_script, directly or through extends.
services.<name>.runCommand that starts the service. A string runs with /bin/sh -c, so pipes, && and multi-line scripts work; a list is an argv run directly without a shell. It starts in the project file's directory unless cwd is set. devlanes runs it exactly as written, so it cannot be combined with preset; prefer run_script when the command is a script in a project file. Exactly one of run and run_script is required after templates are applied. In a list, an item that is one ${{ }} expression giving a number or true/false becomes its text, such as --port followed by ${{ self.port }}.
A Rust service, a Go service run with go run, or a Java service without dev mode or DevTools rebuilds when you restart it:
$ devlanes restart apiIf devlanes picks the wrong runtime
Section titled “If devlanes picks the wrong runtime”devlanes tells the runtime from the script’s file or the service’s folder. A folder with a package.json counts as Node, and one with a Cargo.toml as Rust, so set the runtime on another service there:
services: api: platform: pythonservicesLong-running processes of each lane, started together after infrastructure, setup and lane.start tasks. Each service gets its own port as PORT and, with hosts, HTTPS hostnames. A service that exits shows as failed and is not restarted.
services.<name>A long-running process started with the lane, such as a dev server or a worker. Each service gets its own port from the lane's block (PORT, ${{ self.port }}); devlanes stops it with the lane and never restarts it when it exits. A service needs run or run_script, directly or through extends.
services.<name>.platformRuntime of the service: node, bun, deno, python, rust, go or java. It decides which variables devlanes adds, such as the devlanes CA (NODE_EXTRA_CA_CERTS, SSL_CERT_FILE, a trust store in JAVA_TOOL_OPTIONS) and color settings. Detected from the run_script file or the working directory when omitted; set it only when detection is wrong, such as java for a java -jar command in a folder without a pom.xml or Gradle file. none skips detection and adds no platform variables.
A service counts as Java when its script is in, or its folder holds, a pom.xml or Gradle file. One that runs java -jar from a folder without either needs platform: java.
If a service calls another hostname over HTTPS
Section titled “If a service calls another hostname over HTTPS”devlanes points these runtimes at its CA, so remove any setting that turns certificate checks off. Trust the devlanes CA covers other runtimes.
Go programs built without cgo look lane hostnames up in DNS; Fix programs that cannot resolve *.localhost makes them resolve.