Back to articles
tsx Has a Free API That Runs TypeScript Files Instantly Without Compilation

tsx Has a Free API That Runs TypeScript Files Instantly Without Compilation

via Dev.to JavaScriptAlex Spinov

tsx is the fastest way to run TypeScript in Node.js. No tsconfig. No build step. Just tsx file.ts and it runs. Run TypeScript Instantly # Run any .ts file tsx server.ts # Run .tsx files tsx app.tsx # Watch mode — auto-restart on changes tsx watch server.ts # Run with Node.js flags tsx --inspect server.ts tsx --env-file = .env server.ts Why tsx Over ts-node? Feature tsx ts-node Startup Instant (esbuild) Slow (tsc) Config needed None tsconfig.json ESM support Works Complicated CJS support Works Works Watch mode Built-in Needs nodemon Path aliases Automatic Needs config Use Cases Scripts // scripts/seed-db.ts import { PrismaClient } from " @prisma/client " ; const prisma = new PrismaClient (); const products = [ { title : " Widget " , price : 29.99 , url : " https://example.com/widget " }, { title : " Gadget " , price : 49.99 , url : " https://example.com/gadget " }, ]; for ( const product of products ) { await prisma . product . create ({ data : product }); } console . log ( `Seeded ${ p

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
3 views

Related Articles