import { spawn } from "node:child_process"; const children = [ spawn("npm", ["run", "dev:api"], { stdio: "inherit", env: process.env }), spawn("npm", ["run", "dev"], { stdio: "inherit", env: process.env }), ]; let shuttingDown = false; function shutdown(signal) { if (shuttingDown) return; shuttingDown = true; for (const child of children) { child.kill(signal ?? "SIGTERM"); } } process.on("SIGINT", () => shutdown("SIGINT")); process.on("SIGTERM", () => shutdown("SIGTERM")); for (const child of children) { child.on("exit", (code) => { shutdown("SIGTERM"); process.exit(code ?? 0); }); }