NODEJS Contents

DB Connection Lifecycle (Open/Close, Pool Hygiene)

Connection lifecycle management prevents leaks and ensures graceful shutdown in production environments.

On this page

Lifecycle Management

Database connections must be released back to the pool after use. Leaked connections exhaust resources.

Graceful Shutdown

process.on('SIGTERM', async () => {
  await pool.end();
  process.exit(0);
});

Production Insight

Always close connections during shutdown to avoid orphaned sessions.