10LOC

#sigterm

Node.jsintermediate

Graceful shutdown: draining connections on SIGTERM

import { createServer } from "node:http";

const server = createServer((_req, res) => {
  setTimeout(() => res.end("ok"), 50); // pretend this request takes a moment
});

Stop accepting new connections on SIGTERM, let in-flight requests finish, and force-exit if draining takes too long.