Open In App

How to execute TypeScript file using command line?

Last Updated : 05 Feb, 2020
Like Article


TypeScript is an open-source programming language. It is developed and maintained by Microsoft. TypeScript follows JavaScript syntactically but adds more features to it. It is a superset of JavaScript. In order to execute or run any typescript file, first you need to install node and using it install typescript globally in your local system.


  • To check node is installed, run command if not you have to installed it first:
    node -v
  • Now to install typescript, use:
    npm install -g typescript

After installing typescript, create a .ts file, for example, greet.ts as given below:

  • Example:

    var greet: string = "Greetings"
    var geeks: string = "GeeksforGeeks"
    console.log(greet + " from " + geeks); 
    // save the file as hello.ts 


  • Output:
    Greetings from GeeksforGeeks

Procedure 1: This typescript file greet.ts will create a javascript file at runtime with the same name. To run any typescript file there are a few ways:

  • Step 1: First, run the typescript file with the following command. This will create a javascript file from typescript automatically with the same name.
    tsc helloWorld.ts
  • Step 2:Now run the javascript file, the greet.ts file will get executed:
    node helloWorld.js

Procedure 2: You can merge both the commands by using a pole | and && like below :

  • In Windows:
    tsc greet.ts | node greet.js
  • In Linux or MacOS:
    tsc helloWorld.ts && node helloWorld.js

Procedure 3: You can also install ts-node along with typescript using the following command:


  • To install:
    npm install -g ts-node
  • To run:
    ts-node helloWorld.ts

Output: Using any of the three ways, the output will remain the same.

Greetings from GeeksforGeeks

Previous Article
Next Article

Similar Reads

How to execute PHP code using command line ?
PHP Installation for Windows Users: Follow the steps to install PHP on the Windows operating system. Step 1: First, we have to download PHP from it's official website. We have to download the .zip file from the respective section depending upon on our system architecture(x86 or x64). Step 2: Extract the .zip file to your preferred location. It is r
2 min read
Which command is used to run SASS code from the command line ?
In this article, we will discuss how to run SASS code from the command line. SASS (Syntactically Awesome Style Sheet) is a simple CSS pre-processor that makes it possible to create manageable, platform-independent, and reusable style sheets for websites. It is fully compatible with every version of CSS. Sass reduces the repetition of CSS and theref
3 min read
How to Enable Decorators in TypeScript via Command Line ?
Decorators are a feature of TypeScript that allows you to annotate and modify classes, methods, properties, and parameters at design time. They are used to add metadata or behavior to these entities. To enable decorators, you need to configure TypeScript to use the experimentalDecorators flag. In this article, we will see how to enable decorators i
5 min read
How to Read a File Line by Line using Node.js ?
The ability to Read a File Line by Line allows us to read large files without entirely storing them in memory. It is useful in saving resources and improving the efficiency of the application. It allows us to look for the information that is required and once the relevant information is found, we can stop the search process and can prevent unwanted
3 min read
How to read a Large File Line by Line in PHP ?
We will use some file operations to read a large file line by line and display it. Read a file: We will read the file by using fopen() function. This function is used to read and open a file. Syntax: fopen("filename", access_mode); Parameter: filename: Filename is the name of the file access_mode: It is the mode of the file that includes r - read m
2 min read
How to generate TypeScript definition file from any .js file?
A TypeScript definition file or a type declaration file is any TypeScript file that has the .d.ts filename extension. These files are only meant to hold the type declarations of that particular script and not the source code itself. This means that they are not a part of the compilation process. In this article, we will see how to generate a TypeSc
2 min read
How to execute PHP Script in Website using XAMPP webserver ?
First we have to install the XAMPP/WAMP webserver in our system. Please follow the link to download and install XAMPP/WAMP server. Link After successful installation, the steps we should follow are- Open XAMPP control panel, if you want to link database to your code then start MySQL otherwise you will nee
2 min read
How to execute an SQL query and fetch results using PHP ?
In this article, we will discuss how to execute an SQL query and how to fetch its result? We can perform a query against the database using the PHP mysqli_query() method. Syntax: We can use the mysqli_query( ) method in two ways: Object-oriented styleProcedural style Parameters: connection: It is required that specifies the connection to use.query:
3 min read
How to measure time taken by a function to execute using JavaScript ?
This article will show how to measure the time taken by a function to execute using Javascript. To measure the time taken by a function to execute we have three methods: Table of Content Using the Using Date ObjectUsing the methodUsing the console.time() methodMethod 1: Using the Using Date ObjectWe can use the Date object to calc
3 min read
Command Line Arguments in ElectronJS
ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime. The Command-line arguments are parameters that are
6 min read