node-opslisted
Install: claude install-skill AllThingsSmitty/agent-skills
# Production Node.js Operations
A Node.js app that works in development often has silent operational problems in production: it crashes on uncaught errors, drops in-flight requests during deploys, leaks memory over time, or gives load balancers no way to know it's ready. These are all fixable — and they should be addressed before the first production deploy, not after the first incident.
## Graceful shutdown
When a container or process manager sends `SIGTERM`, the app has a window to finish what it's doing before it's killed. If you don't handle it, the process exits immediately and drops every in-flight request.
```ts
const server = app.listen(3000);
process.on('SIGTERM', () => {
server.close(() => {
// connections drained — exit cleanly
process.exit(0);
});
// Safety valve: force exit if drain takes too long
setTimeout(() => process.exit(1), 10_000).unref();
});
```
`server.close()` stops accepting new connections and waits for existing ones to finish. The timeout prevents the app from hanging indefinitely if a connection never closes (e.g., a long-polling client).
For database connections, message consumers, or other resources: close them in the `SIGTERM` handler too, after the HTTP server has stopped accepting work.
## Handle uncaught exceptions and unhandled rejections
An uncaught exception or unhandled rejection leaves the process in an indeterminate state. The safest response is to log the error and exit �� let the process manager restart you.