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
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.
export type Note = { id: number; text: string; createdAt: string };
That is types.ts. It exports only a type.
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:
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.
enum Color { Red, Green }
console.log(Color.Red);
Running this file fails with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. An erasable replacement is a constant object:
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:
{
"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.
Cloud
More like this
Cloud
Build a Tiny JSON API With Axum: Rust on the Web in Fifteen Minutes
Your Rust programs have been talking to the terminal. Time they talked to the internet. Build a notes API with Axum, with routes, JSON in and out, shared state and proper 404s, in about 50 lines.
Cloud
Ollama Review: Running Local LLMs on Your Own Machine, No Cloud Required
What if your AI assistant lived in your basement instead of someone else's data centre? A review of Ollama: how to run local LLMs with it, what hardware you really need, the API that makes it useful, and where it falls short.
Cloud
Async Rust With Tokio: Build an Echo Server That Juggles a Thousand Clients
One waiter, forty tables, and nobody waits for their soup. That's async. Learn async Rust with Tokio by building a 30-line TCP echo server, then meet the one mistake that freezes the whole restaurant.