Node.js (NestJS)

NestJS services.

NestJS services. Its BLOCKER tier is almost all boundary and concurrency discipline specific to a singleton-based DI framework: unvalidated DTOs, request-scoped data leaking across users via singleton providers, the event loop blocked by sync APIs, errors swallowed into a generic 500. The HIGH tier is mostly architecture — logic that belongs in a service ending up in a controller, N+1 ORM queries, HTTP clients built without the shared interceptor stack.

Which repositories get it

A repository on any of these 2 profiles: fullstack-react-node, service-node. redline init detects the profile and --profile overrides it — see Profiles & stacks.

Within such a repository, a file gets these rules when it matches one of these globs:

  • src/**/*.ts
  • apps/**/src/**/*.ts
  • libs/**/src/**/*.ts
  • packages/**/src/**/*.ts

The 20 rules

When a review comment cites one of these ids, this is where to look up what it catches. Of the 20, 7 BLOCKER, 9 HIGH and 4 SUGGESTION. A finding from this file opens like this:

a finding from this file
Redline/BLOCKER [nodejs/floating-promises]: <one-line problem>

What each severity obliges you to do is on The output contract.

Rule idSeverityCatches
nodejs/floating-promisesBLOCKERFloating promises. Every promise is `await`ed, returned, or explicitly handled with `.catch` — an unhandled rejection crashes the process on modern Node.
nodejs/blocking-event-loopBLOCKERBlocking the event loop. Sync APIs in request paths (`fs.*Sync`, `child_process.execSync`, `crypto.pbkdf2Sync`), or CPU-heavy loops/JSON parsing of large payloads without worker threads.
nodejs/missing-dto-validationBLOCKERMissing validation at the boundary. Request DTOs must use `class-validator` decorators with a global `ValidationPipe` (`whitelist: true`); no raw `@Body() body: any`.
nodejs/request-state-on-singletonBLOCKERRequest-scoped data in singleton providers. NestJS providers are singletons by default — storing per-request state on `this` bleeds data across users. Use `REQUEST` scope deliberately or AsyncLocalStorage.
nodejs/await-in-loopBLOCKER`await` in a loop for independent operations — require `Promise.all` / `Promise.allSettled` with a bounded batch size.
nodejs/config-outside-configserviceBLOCKERSecrets/config read via `process.env` scattered through code — access only through the typed `ConfigService`/config module, validated at startup (fail fast on missing).
nodejs/error-detail-swallowedBLOCKERErrors caught and converted to generic 500 with details swallowed — use exception filters; preserve cause in logs (structured), never in the response body.
nodejs/logic-in-controllerHIGHBusiness logic in controllers — controllers translate HTTP only; logic lives in providers/services.
nodejs/forwardref-circular-dependencyHIGHCircular module dependencies "solved" with `forwardRef` where extraction of a shared module is possible.
nodejs/raw-http-clientHIGHRaw `axios`/`fetch` calls without timeout, and without going through the service's shared HTTP client (interceptors carry auth, tracing, retries).
nodejs/missing-guardHIGHNew endpoint missing guard coverage (authn/authz) — verify global guard applies or explicit guard present.
nodejs/orm-n-plus-oneHIGHTypeORM/Prisma queries inside loops (N+1) — batch with `In()`/`findMany`.
nodejs/transaction-spans-remote-callHIGHTransactions spanning external HTTP calls or message publishes.
nodejs/json-parse-external-inputHIGH`JSON.parse` on external input without size limits or try/catch at the boundary.
nodejs/missing-listener-teardownHIGHEvent emitter / interval / stream listeners registered without teardown in `onModuleDestroy`.
nodejs/console-loggingHIGHLogging via `console.*` instead of the injected structured logger.
nodejs/dto-input-output-sharedSUGGESTIONDTO classes reused for both input and output — split; output shape is a contract.
nodejs/lazy-import-heavy-modulesSUGGESTIONHeavy modules imported at top level but used in one rarely-hit path — lazy import.
nodejs/magic-valuesSUGGESTIONMagic status codes/strings — use `HttpStatus` and shared enums.
nodejs/hot-loop-allocationSUGGESTIONRepeated `Date.now()` / `new Intl.*` in hot loops — hoist.

Changing a rule

Edit standards/stacks/nodejs.md and nowhere else. Every other copy is generated from it. A merged change reaches every onboarded repository as a pull request, so treat it as a production change.

Rule ids are permanent. Reword a rule freely; it keeps its id. Renaming or removing an id orphans every telemetry record that cited it.

  1. Edit the markdownstandards/ is the only place a human edits a rule. AGENTS.md, CLAUDE.md, .github/copilot-instructions.md and .github/instructions/ are rendered from it, and the next render overwrites any hand edit there.
  2. node scripts/assign-rule-ids.mjsAssigns a permanent <stack>/<slug> id to any new rule bullet and rewrites the file in place. Do not invent an id by hand. CI runs the same script with --check and fails if a rule is missing one.
  3. node scripts/render-self.mjsRe-renders this repository's own copies of those files. CI runs it with --check, so a stale copy fails the build.
  4. Bump standards/manifest.json → versionIn the same pull request as the rule change. Sync pull requests quote the version, so every repository can tell which standards it is on.
  5. Add a CHANGELOG.md entryAlso in the same pull request. Say what changed and why, and record the seed score: a standards change with no measurement is an opinion.
  6. node scripts/validate.mjsThe self-check CI runs: the manifest is consistent, rule ids are well formed, the output contract is intact, and every glob is one Copilot can read.

The full file

standards/stacks/nodejs.md · 35 lines · 3.3 KB
# Node.js (NestJS) Service Review Rules

**Scope:** server-side TypeScript in a NestJS service. Do not apply these rules to
`.tsx` files, test specs, or front-end code; if you see React in the file, this rule
set does not apply.

## BLOCKER — request changes

- `nodejs/floating-promises` — **Floating promises.** Every promise is `await`ed, returned, or explicitly handled with `.catch` — an unhandled rejection crashes the process on modern Node.
- `nodejs/blocking-event-loop` — **Blocking the event loop.** Sync APIs in request paths (`fs.*Sync`, `child_process.execSync`, `crypto.pbkdf2Sync`), or CPU-heavy loops/JSON parsing of large payloads without worker threads.
- `nodejs/missing-dto-validation` — **Missing validation at the boundary.** Request DTOs must use `class-validator` decorators with a global `ValidationPipe` (`whitelist: true`); no raw `@Body() body: any`.
- `nodejs/request-state-on-singleton` — **Request-scoped data in singleton providers.** NestJS providers are singletons by default — storing per-request state on `this` bleeds data across users. Use `REQUEST` scope deliberately or AsyncLocalStorage.
- `nodejs/await-in-loop` — **`await` in a loop for independent operations** — require `Promise.all` / `Promise.allSettled` with a bounded batch size.
- `nodejs/config-outside-configservice` — **Secrets/config read via `process.env` scattered through code** — access only through the typed `ConfigService`/config module, validated at startup (fail fast on missing).
- `nodejs/error-detail-swallowed` — **Errors caught and converted to generic 500 with details swallowed** — use exception filters; preserve cause in logs (structured), never in the response body.

## HIGH

- `nodejs/logic-in-controller` — Business logic in controllers — controllers translate HTTP only; logic lives in providers/services.
- `nodejs/forwardref-circular-dependency` — Circular module dependencies "solved" with `forwardRef` where extraction of a shared module is possible.
- `nodejs/raw-http-client` — Raw `axios`/`fetch` calls without timeout, and without going through the service's shared HTTP client (interceptors carry auth, tracing, retries).
- `nodejs/missing-guard` — New endpoint missing guard coverage (authn/authz) — verify global guard applies or explicit guard present.
- `nodejs/orm-n-plus-one` — TypeORM/Prisma queries inside loops (N+1) — batch with `In()`/`findMany`.
- `nodejs/transaction-spans-remote-call` — Transactions spanning external HTTP calls or message publishes.
- `nodejs/json-parse-external-input` — `JSON.parse` on external input without size limits or try/catch at the boundary.
- `nodejs/missing-listener-teardown` — Event emitter / interval / stream listeners registered without teardown in `onModuleDestroy`.
- `nodejs/console-logging` — Logging via `console.*` instead of the injected structured logger.

## SUGGESTION

- `nodejs/dto-input-output-shared` — DTO classes reused for both input and output — split; output shape is a contract.
- `nodejs/lazy-import-heavy-modules` — Heavy modules imported at top level but used in one rarely-hit path — lazy import.
- `nodejs/magic-values` — Magic status codes/strings — use `HttpStatus` and shared enums.
- `nodejs/hot-loop-allocation` — Repeated `Date.now()` / `new Intl.*` in hot loops — hoist.