0
0
Typescriptprogramming~15 mins

Running TypeScript with ts-node - Mini Project: Build & Apply

Choose your learning style9 modes available
Running TypeScript with ts-node
📖 Scenario: You want to quickly run TypeScript code without compiling it manually. Using ts-node lets you run TypeScript files directly, like running JavaScript with node.This is useful when testing small scripts or learning TypeScript without extra setup.
🎯 Goal: Learn how to write a simple TypeScript file and run it directly using ts-node.
📋 What You'll Learn
Create a TypeScript file with a simple variable and a function
Use ts-node to run the TypeScript file directly
Print output to the console
💡 Why This Matters
🌍 Real World
Developers often want to quickly test TypeScript code snippets without compiling. ts-node helps run TypeScript files directly, speeding up development and learning.
💼 Career
Knowing how to run TypeScript code efficiently is useful for frontend and backend developers working with TypeScript in real projects.
Progress0 / 4 steps
1
Create a TypeScript file with a greeting variable
Create a variable called greeting and set it to the string "Hello from TypeScript!".
Typescript
Need a hint?

Use const greeting: string = "Hello from TypeScript!"; to declare the variable.

2
Add a function to print the greeting
Add a function called printGreeting that takes no parameters and prints the greeting variable using console.log.
Typescript
Need a hint?

Define function printGreeting(): void { console.log(greeting); }.

3
Call the function to display the greeting
Call the function printGreeting() to display the greeting message.
Typescript
Need a hint?

Simply write printGreeting(); to call the function.

4
Run the TypeScript file using ts-node
Run the TypeScript file using the command ts-node filename.ts in your terminal to see the output.
Typescript
Need a hint?

Open your terminal and run ts-node filename.ts where filename.ts is your file name.