Run TypeScript Without Compiling
- Mohammad Abu Mattar
- Programming
- 02 Dec, 2022
- 02 Mins read
Introduction
In this post, I will show you how to run TypeScript without compiling it to JavaScript. This is useful for debugging and testing. In this post, I will show you how to do it.
Setup a TypeScript Project
Step 1: Create a Directory
Create a directory for the project.
Step 2: Initialize a Node.js Project
Initialize a Node.js project.
Step 3: Install TypeScript and @types/node
Install TypeScript and @types/node
.
Step 4: Initialize a TypeScript Project
Initialize a TypeScript project.
Step 5: Create a TypeScript File
Create a TypeScript file.
Step 6: Example Code
Add the following code to the TypeScript file.
Step 7: Run the TypeScript File
Now, we will install ts-node
and run the TypeScript file.
Add the following code to the package.json
file.
NOTE:
nodemon
is a utility that will monitor for any changes in your source and automatically restart your server. You can install it usingyarn global add nodemon
ornpm install -g nodemon
.
Run the TypeScript file.
Conclusion
I demonstrated how to run TypeScript in this article without converting it to JavaScript. For testing and troubleshooting, this is helpful. I demonstrate how to accomplish that in this post.