Frameworks
Go and Rust
Build a binary and run it.
Compile in the build command, run the binary in the run command, and listen on PORT.
If your program listens on a different fixed port (for example 8080), we notice after a few seconds and follow it, so the deploy still succeeds. It is still best to read PORT, so the port is always the one you expect. Your program must listen on 0.0.0.0; one that listens only on its own local address cannot be reached, and the deploy log tells you so.
Go#
| Setting | Value |
|---|---|
| Build command | go build -o server . |
| Run command | ./server |
The pattern is go build -o <program-name> <folder-with-main.go>:
<program-name>is the program file the build creates. After the build,./<program-name>is the program itself.<folder-with-main.go>is the folder that contains yourmain.go:.when it is in the project root, or for example./cmd/apiwhen it is incmd/api.
go build -o server . # run command: ./server
go build -o myapp ./cmd/api # run command: ./myappDo not commit a folder with the same name as the output. If server/ already exists as a folder, Go puts the program inside it (as server/<module-name>) and ./server is then a folder, not a program.
port := os.Getenv("PORT")
if port == "" { port = "3000" }
log.Fatal(http.ListenAndServe("0.0.0.0:"+port, handler))Rust#
| Setting | Value |
|---|---|
| Build command | cargo build --release |
| Run command | ./target/release/your-binary-name |
Bind to 0.0.0.0 and read the port from the PORT environment variable. The first build compiles all dependencies and can take several minutes; later builds reuse downloaded packages and are faster. After a successful build we keep only your finished program, so the run command must start the compiled file (./target/release/your-binary-name), not cargo run.
Libraries your build needs#
A common C toolchain is included. If your project needs more system libraries (for example postgresql-dev or protobuf-dev), list them in an environment variable:
SYSTEM_PACKAGES=postgresql-dev protobuf-devSeparate names with spaces or commas. They are installed before your build runs.