Skip to content

graceful

graceful(handler, options?): Promise<{ server: Server<typeof IncomingMessage, typeof ServerResponse>; shutdown: (signal) => Promise<void>; }>

Defined in: lifecycle.js:48

Creates and manages a graceful HTTP server lifecycle.

Function

HTTP request handler (req, res) => void

Lifecycle configuration

(code?) => void

Exit function (override for testing)

string

Hostname to bind to

{ error: (…args) => void; info: (…args) => void; warn: (…args) => void; }

Logger with .info(), .warn(), .error() methods

(…args) => void

(…args) => void

(…args) => void

(ctx) => void | Promise<void>

Hook called after server.close(). Receives {log, signal}. Errors are caught and logged; shutdown continues.

(ctx) => void | Promise<void>

Hook called before server.listen(). Receives {log}. Rejection prevents the server from starting.

number

Port to listen on

string[]

OS signals that trigger shutdown

number

Maximum time (ms) to wait for connections to drain

Promise<{ server: Server<typeof IncomingMessage, typeof ServerResponse>; shutdown: (signal) => Promise<void>; }>