Skip to main content

Node — Flush and shutdown

Flush queued events immediately with flush(), or stop the flush timer and flush with shutdown() before process exit. Both are async (return a Promise).

flush()

Flush all queued events to the server immediately.
Use when you need to ensure events are sent before a response or before the process exits (e.g. in a serverless function or after a critical path).

shutdown()

Stop the flush timer and flush remaining events. Call before process exit for graceful shutdown.
Use in cleanup handlers (e.g. process.on('SIGTERM', ...)) so no events are lost when the process exits.

See also