Node.js and TypeScript
TypeScript adds types, editor support, and safer refactors to Node projects. Node does not execute TypeScript source directly in the usual runtime path; you compile it or run it through a TypeScript-aware loader.
How it runs
- Write
.tsfiles. - Use a compiler or runtime loader such as
tsc,tsx, orts-node. - Run the generated JavaScript or the loader command inside Node.
Common tooling
- tsc for compiling TypeScript to JavaScript.
- tsx for fast local execution during development.
- ts-node for direct TypeScript execution in some workflows.
Recommended structure
src/
app.ts
config/
routes/
services/
types/
dist/
app.js
Typing guidelines
- Type public function inputs and outputs first.
- Prefer explicit domain types over repeated inline object shapes.
- Keep runtime validation even when types exist, because external input is still untrusted.
Practice
- Create one
.tsfile with a typed function. - Choose one tool to run or compile it.
- Record whether you prefer compile-first or loader-first execution for local development.