Skip to main content
Lightning provides two ways to start your server: app.Run() for simple cases and app.RunGraceful() when you need to finish in-flight requests before the process exits.

app.Run()

app.Run() starts the server and blocks until the server encounters an error. Pass an address string to bind to a specific host and port.
When you call app.Run() with no arguments, the server listens on :6789 by default. You can also override the port by setting the PORT environment variable.
app.Run() does not handle OS signals. Sending SIGINT (Ctrl+C) or SIGTERM terminates the process immediately without waiting for active connections to complete.

app.RunGraceful()

app.RunGraceful(shutdownTimeout, address) listens for SIGINT and SIGTERM. When either signal arrives, it calls the underlying server’s shutdown method and waits up to shutdownTimeout seconds for active connections to finish.
If shutdownTimeout is zero or negative, it defaults to 5 seconds. Like app.Run(), the address argument is optional — omit it to fall back to :6789.

app.Shutdown()

Call app.Shutdown() to trigger a graceful shutdown programmatically (for example, from a signal handler you manage yourself or from a test).
Calling Shutdown() before the server has started is a no-op.

Complete Example

When you stop the process with Ctrl+C or kill <pid>, you will see:
Prefer RunGraceful in production so that long-running requests (database queries, file uploads) are not cut off mid-flight during deployments or container restarts.