AZ.dev

Node.js

Runtime APIs, module system, and server-side patterns

How-To Guides

Run a TypeScript file with node and no build step
Current Node runs .ts files by stripping the type annotations.
typescriptstrip-typesnodeesmtsx
Fail a Node script without cutting off its output
Set process.exitCode and let the script end on its own.
processexitexitCodestdoutcli
Give a fetch call a timeout
Pass AbortSignal.timeout() as the request's signal.
fetchtimeoutAbortSignalAbortControllerhttp
A storage URL builder and its static file handler must share one prefix constant
When a storage abstraction returns URLs that the app's static-file handler is supposed to serve, the two must agree on the path prefix.
fastifystatic-filesimage-storageurlsdebugging
Content-hash dedup that restores a soft-deleted row must re-run quota and limit checks
Content-hash dedup is supposed to be free: same bytes, same row, no charge.
dedupsoft-deletequotarace-conditionpostgres
Serialize per-user check-then-write flows with pg_advisory_xact_lock(hashtext(id))
When the same user can race against themselves on a check-then-write flow (multi-tab uploads, double-clicked submits), wrap the whole flow in a transaction holding a per-user advisory lock.
postgresprismaconcurrencyadvisory-lockquota
Reproduce Railway's npm ci locally with the exact npm version
When a Railway deploy fails with npm ci errors that don't reproduce locally, the cause is almost always a different npm version.
npmnpm-cirailwayrailpackpackage-lock

Error Solutions

Fix "Cannot find module" with ES modules in Node.js
Node.js ES modules require explicit file extensions in import paths.
esmmodulesimportextensions