This guide explains how to run TypeScript files directly using ts-node
, bypassing the need to manually compile the .ts
files into .js
.
- Node.js installed on your machine. You can download it from Node.js official website.
- NPM (Node Package Manager), which comes with Node.js.
-
Install ts-node and TypeScript:
Open your terminal and run the following command to install bothts-node
and the TypeScript compiler globally:npm install -g ts-node typescript
-
Run Your TypeScript File:
Navigate to the directory containing your.ts
file and run it directly usingts-node
:npx ts-node yourfile.ts
Replace yourfile.ts
with the path to your TypeScript file.
- ts-node simplifies the development process by allowing you to execute TypeScript code directly without pre-compilation.
- For more complex projects, consider setting up a
tsconfig.json
file to customize compiler options.