Graceful Shutdown for a Node Server
Make a Node server shut down cleanly when the platform sends SIGTERM. In-flight requests finish or time out. The process does not hang forever. SERVER [FRAMEWORK] What is in flight: [HTTP, A POOL, A QUEUE WORKER] Platform stop grace: [SECONDS] Database pool: [LIBRARY] DELIVER 1) On SIGTERM: stop accepting new connections, mark readiness as failing so the load balancer leaves, wait for in-flight requests up to a timeout shorter than the platform grace, then close the pool and exit 0. 2) On the timeout: exit non-zero so we can see it, after attempting to close. 3) The worker variant: stop taking new jobs, finish the current one or return it to the queue if the platform is about to kill us. Do not ack a job we did not finish. 4) A local way to test: send the signal and show which log line we expect. 5) The bug to avoid: a server that listens for SIGTERM and then never exits because a handle is open. Name the handle (pool, timer, stream). Do not add a second listener that calls process.exit immediately and skips the drain.
🌟 Example Output / Preview
Prompt Metadata
Primary Use Cases:
- •Legacy code modernization & technical refactoring
- •Full-stack layout generation & component structuring
- •CI/CD workflow automation & unit/E2E testing suites
Associated Tags:
💡 Pro Tips & Advice
1. Use bracketed items: Be sure to fill out all [PLACEHOLDER] elements with specific details before sending the prompt to the AI model.
2. Adjust temperature: For creative tasks, set AI temperature higher (e.g., 0.8), or lower (e.g., 0.2) for strict coding/technical tasks.
🔗 Related AI Prompts
Full SaaS Landing Page Build Spec (SEO + Conversion)
You are a Staff Product Designer + Frontend Engineer + SEO strategist. Build a complete, production-ready marketing landing page f...
SaaS Analytics Dashboard Full Build Spec
You are a Principal Product Designer + Frontend Lead. Design and specify a complete [LIGHT | DARK] analytics dashboard for [PRODUC...
SaaS Admin Panel Dashboard Build Spec
Design a full internal Admin Dashboard for [PRODUCT_NAME] used by [ADMIN_ROLE: support | ops | super-admin]. --- 🎯 CONTEXT Adm...