Skip to content

fix(templates): boot the Fastify starter on an empty PORT and a prod install - #31

Merged
Bccorb merged 1 commit into
mainfrom
fix/fastify-port-and-pino-pretty
Jul 30, 2026
Merged

fix(templates): boot the Fastify starter on an empty PORT and a prod install#31
Bccorb merged 1 commit into
mainfrom
fix/fastify-port-and-pino-pretty

Conversation

@Bccorb

@Bccorb Bccorb commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Two ways the Fastify starter came up wrong. Neither is caught by the build or by lint, and both were found reviewing #28 after it merged.

Empty PORT bound a random port

PORT was read with ??, which only guards null and undefined. An empty PORT= in .env reached Number(""), which is 0, and Fastify binds port 0 to a random free port. The API started, reported success, and listened somewhere nothing was pointed at.

Reading it with || treats the empty value as missing, which is what the Express starter already does.

PORT before after
unset 3000 3000
PORT= 0 (random) 3000
PORT=8080 8080 8080

pino-pretty was a dev dependency loaded at runtime

The logger wires up the pino-pretty transport for any NODE_ENV other than production. With the package in devDependencies, npm ci --omit=dev, which is the usual shape of a staging deploy, left the transport target unresolvable and the process died on startup.

It moves to dependencies, since every environment that loads it needs it at runtime. Production still emits JSON and never loads the transport.

Verification

  • npm run validate passes
  • npm ci, npm run build, npm run lint in templates/api/fastify all clean
  • Confirmed pino-pretty resolves under npm ci --omit=dev with NODE_ENV=staging
  • Confirmed an empty PORT now falls back to 3000

Patch changeset included.

…install

Two ways the Fastify starter came up wrong, both outside what the build and lint
catch.

PORT was read with `??`, which only guards null and undefined. An empty `PORT=`
in .env reached `Number("")`, which is 0, and Fastify binds port 0 to a random
free port, so the API started somewhere nobody was looking instead of on 3000.
Reading it with `||` treats the empty value as missing, matching the Express
starter.

pino-pretty moves to dependencies. The logger wires it up for any NODE_ENV other
than production, so `npm ci --omit=dev`, the usual shape of a staging deploy,
left the transport target unresolvable and the process died on startup. It is a
runtime dependency in every environment that loads it.

Verified with npm run validate, and with npm ci, npm run build, and npm run lint
in the template. Confirmed pino-pretty resolves under `npm ci --omit=dev` with
NODE_ENV=staging, and that an empty PORT now falls back to 3000.
@Bccorb
Bccorb merged commit 6d5a047 into main Jul 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant