Run TypeScript in Node.js With No Build Step: A Ten-Minute Lab

Type stripping is stable in Node.js 24.12 and 25.2+, so `node server.ts` just works. Build a tiny notes API with no build step, see the four syntax features that break, and set up tsc as a checker only.

Ada Brackett

4 min read

You can now run TypeScript in Node directly. Type stripping, which lets Node execute .ts files by erasing the type annotations, became stable in Node.js v25.2.0 and v24.12.0. In this post we will build a small HTTP service in TypeScript, run it with no build step, look at what does not work, and set up the compiler as a type checker. Everything here was checked against the Node.js TypeScript documentation and run on Node.js 26.11.1 on 29 October 2026.

How type stripping works

Node replaces type annotations with whitespace and runs what is left as JavaScript. It does not type-check your code, and it ignores tsconfig.json. The feature arrived in v22.6.0 behind a flag, was enabled by default in v23.6.0 and v22.18.0, stopped printing an experimental warning in v24.3.0, and was marked stable in v25.2.0 and v24.12.0. Node 26.0.0 removed the old --experimental-transform-types flag.

Step 1: hello, types

TypeScript
type User = { name: string; visits: number };

function greet(user: User): string {
  return `Hello, ${user.name}! Visit number ${user.visits}.`;
}

console.log(greet({ name: "Ada", visits: 3 }));

Save it as greet.ts and run node greet.ts. The type and the annotations are erased; the template string runs.

Step 2: a tiny notes API

Create a folder with a package.json containing {"type":"module"}, then two files.

TypeScript
export type Note = { id: number; text: string; createdAt: string };

That is types.ts. It exports only a type.

TypeScript
import { createServer } from "node:http";
import type { Note } from "./types.ts";

const notes: Note[] = [];

const server = createServer((req, res) => {
  if (req.method === "POST" && req.url === "/notes") {
    let body = "";
    req.on("data", (chunk) => (body += chunk));
    req.on("end", () => {
      const note: Note = {
        id: notes.length + 1,
        text: body.trim(),
        createdAt: new Date().toISOString(),
      };
      notes.push(note);
      res.writeHead(201, { "content-type": "application/json" });
      res.end(JSON.stringify(note));
    });
    return;
  }
  if (req.method === "GET" && req.url === "/notes") {
    res.writeHead(200, { "content-type": "application/json" });
    res.end(JSON.stringify(notes));
    return;
  }
  res.writeHead(404).end();
});

server.listen(3000, () => console.log("listening on http://localhost:3000"));

That is server.ts: a POST adds a note, a GET lists them, anything else is a 404. Two details matter. The import uses import type, because only imports marked type are removed; a plain import of a type fails at runtime. And the import includes the .ts extension, which Node requires.

Run it with node server.ts, then try it:

Bash
curl -X POST --data 'buy oat milk' http://localhost:3000/notes
curl http://localhost:3000/notes

The first command returns the new note with an id and a timestamp; the second returns the list.

Step 3: what breaks

Type stripping only handles syntax that can be erased. Features that need TypeScript to generate JavaScript raise ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. The documentation names four: enum declarations, namespaces with runtime code, parameter properties, and import aliases. Decorators produce a parser error.

TypeScript
enum Color { Red, Green }
console.log(Color.Red);

Running this file fails with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. An erasable replacement is a constant object:

TypeScript
const Color = { Red: "red", Green: "green" } as const;
type Color = (typeof Color)[keyof typeof Color];

function paint(c: Color): string {
  return `painting it ${c}`;
}

console.log(paint(Color.Green));

This prints painting it green.

Step 4: keep tsc as the checker

Since Node does not check types, use the TypeScript compiler for that. Install it with npm install -D typescript @types/node and add the configuration the Node documentation recommends for TypeScript 5.8 or newer:

JSON
{
  "compilerOptions": {
    "noEmit": true,
    "target": "esnext",
    "module": "nodenext",
    "rewriteRelativeImportExtensions": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true
  }
}

erasableSyntaxOnly reports syntax Node cannot strip, such as the enum above. verbatimModuleSyntax enforces import type. noEmit is optional and suits projects where you only run .ts files; leave it out if you ship .js output. Run npx tsc to check the project.

Type stripping is also unavailable in the REPL, and tsconfig.json features like paths are not applied at runtime.

Try this next

Add a DELETE /notes/:id route, run npx tsc, and see whether the checker catches a mistake you make on purpose. Then try writing a small class with a parameter property and watch both Node and erasableSyntaxOnly reject it.