My Favourite (& Easiest) Way to Run Nodejs App Written in TypeScript
TLTR
Use tsx
loader.
How to Run Nodejs Apps/Scripts Written in TypeScript with Minimal Configuration
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
package.json
{
// ...
"scripts": {
"build": "tsc",
"start": "node --import=tsx src/index.ts"
},
"devDependencies": {
"tsx": "^4.19.4",
"typescript": "^5.8.3"
}
}
Run 🎉
Simply run the command to boot your TypeScript app/script:
yarn run start
TSX is not for running in production
For performance reasons tsx loader is not recommended for production running (only for local development).
In production, always use JS files created in the build step.
Further Reading
If you want to learn more about options "how to" run Nodejs apps written in TypeScript, check this post: The Easier Way To Setup Nodejs App Written in Typescrips - 5 Steps Needed
This article was originally published on https://craftengineer.com/. It was written by a human and polished using grammar tools for clarity.
Follow me on X (Formally, Twitter) or Bluesky.