agentleFS
saizulsaizul/nodejs-backend-skills/skills/node-deploy/SKILL.md

node-deploy

Skill0 starsChanged 3 days agoMITView on GitHub

Deploy Node.js backends to production with Docker, PM2 or systemd - multi-stage Dockerfile (npm ci, prune dev deps, slim base pinned to LTS, non-root node user, exec-form CMD, tini, HEALTHCHECK), .dockerignore, PM2 ecosystem (cluster mode, kill_timeout, wait_ready, zero-downtime reload), hardened systemd unit (dedicated user, EnvironmentFile, Restart, sandboxing), graceful shutdown on SIGTERM (readiness off, drain, server.close, close pools and workers, hard timeout) and liveness/readiness endpoints. Includes a checker for unpinned base images, root containers, devDependencies in images, npm start or shell-form CMD swallowing signals, secrets in ENV or Environment=, .dockerignore gaps, PM2 watch/kill_timeout, systemd root/Restart/hardening, missing SIGTERM handling and health endpoints, and localhost binding (incl. Fastify's default). Use when the user containerises or deploys a Node.js API, sets up PM2 or systemd, sees dropped requests or 502s on deploy, or asks for health checks or graceful shutdown.

  • Reads credentials

The file

Files
SKILL.md

Node.js deploy

Small, non-root images or services that start fast, report health honestly, and finish in-flight work when told to stop. Templates live in assets/; the checker reviews what the project already has.

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • "Dockerize my Node API", "review my Dockerfile", "deploy with PM2 / systemd"
  • Requests fail or 502 during deploys/restarts; containers take 10 s to stop
  • "Add health checks / readiness / liveness", "graceful shutdown"
  • Moving from npm start on a VPS to a supervised service

When not to use

  • Environment variable design and validation: env-config
  • Queue worker shutdown details: background-jobs (this skill wires the process)
  • Cloud-specific IaC (Terraform, Helm charts, ECS task definitions) beyond the probe/ signal settings shown in references
  • Dependency vulnerabilities: package-json-audit

Workflow

  1. Pick the target with the user: Docker/Compose (or Kubernetes), PM2 on a VM, or systemd on a VM. Note Node major, build step (tsc, tsup, none), entry file, port, whether a reverse proxy/load balancer sits in front.
  2. Check what exists (read-only).
    python3 scripts/deploy_check.py .
    python3 scripts/deploy_check.py . --json --min-severity low
    Exit 1 = findings at or above --fail-on (default medium).
  3. Fix high findings first: root user, unpinned base, secrets baked into the image or unit (tell the user to rotate them: image layers and systemctl show expose them), missing SIGTERM handling.
  4. Apply templates (adapt paths, show the diff, wait for approval):
    • Docker: assets/Dockerfile + assets/.dockerignore
    • PM2: assets/ecosystem.config.cjs
    • systemd: assets/node-app.service
    • Lifecycle: assets/lifecycle.mjs for /healthz, /readyz and the shutdown sequence; framework hooks in references/graceful-shutdown.md.
  5. Platform settings from references/targets.md: stop grace period / kill_timeout / TimeoutStopSec above the shutdown time, probes, memory limit and --max-old-space-size, proxy trust proxy and keep-alive timeouts.
  6. Verify (commands for the user to run, or you with permission):
    docker build -t api:test . && docker run --rm -p 3000:3000 --env-file .env api:test
    docker exec <id> id                       # uid=1000(node), not root
    curl -fsS localhost:3000/healthz && curl -fsS localhost:3000/readyz
    time docker stop <id>                     # well under 10 s, exit code 0
    Then the zero-dropped-requests test from the graceful shutdown reference. Re-run the checker.

Output

Deploy review: api (Docker + nginx) - 3 high, 5 medium
HIGH  Dockerfile:1   FROM node (latest) -> node:22-bookworm-slim, multi-stage
HIGH  Dockerfile     runs as root -> USER node, COPY --chown=node:node
HIGH  Dockerfile:5   ENV API_TOKEN baked into the image -> runtime env; rotate the token
MED   Dockerfile:8   CMD npm start (shell form) -> CMD ["node","dist/server.js"] with tini
MED   src/server.js  SIGTERM exits without server.close(); no /readyz -> lifecycle.mjs

After: image 1.1 GB -> 210 MB, docker stop 10.2 s -> 1.4 s, 0 errors during stop under load.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.