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

  1. Write .ts files.
  2. Use a compiler or runtime loader such as tsc, tsx, or ts-node.
  3. 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.
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

  1. Create one .ts file with a typed function.
  2. Choose one tool to run or compile it.
  3. Record whether you prefer compile-first or loader-first execution for local development.