---
title: "Run TypeScript Without Compiling"
lang: "en"
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/post/run-typescript-without-compiling
---

![Blog post image for Run TypeScript Without Compiling - We can 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.](/_astro/hero.EI1J4T1U_1xifw3.webp)

[Home](/)›[Blog](/blog)›[All Categories](/blog/categories)›[TypeScript](/blog/categories/typescript)

Blog

[Prev in TypeScriptCaching Strategies with Redis in Node.js and TypeScript](/blog/post/caching-strategies-with-redis-in-node-js-and-typescript)[Next in TypeScriptSetting up JWT Authentication in TypeScript with Express, MongoDB, Babel, Prettier, ESLint, and Husky - Part 2](/blog/post/setting-up-jwt-authentication-in-typescript-with-express-mongodb-babel-prettier-eslint-and-husky-part-2)

[TypeScript](/blog/categories/typescript)[Node.js](/blog/categories/nodejs)[JavaScript](/blog/categories/javascript)[Development Tools](/blog/categories/development-tools)

# Run TypeScript Without Compiling

[Mohammad Abu Mattar](/authors/mohammad-abu-mattar)Published: 02 Dec 202202 Mins read02 Mins listen

[Markdown for AI(opens in a new tab)](/post/run-typescript-without-compiling/index.md "Open the plain-Markdown version of this page, for pasting into an AI tool")

TL;DR

We can 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.

Series

[Programming Languages](/series/programming-languages)1/2

[NextTypeScript vs. JSDoc: Static Type Checking in JavaScript Compared](/blog/post/typescript-vs-jsdoc-exploring-the-pros-and-cons-of-static-type-checking-in-javascript)

All posts in this series (2)

Blog2

1.  [Run TypeScript Without CompilingYou are here](/blog/post/run-typescript-without-compiling)
2.  [TypeScript vs. JSDoc: Static Type Checking in JavaScript Compared](/blog/post/typescript-vs-jsdoc-exploring-the-pros-and-cons-of-static-type-checking-in-javascript)

### Run TypeScript Without Compiling

Contents

[Introduction](#introduction)[Set up a TypeScript project](#set-up-a-typescript-project)[Step 1: create a directory](#step-1-create-a-directory)[Step 2: initialize a Node.js project](#step-2-initialize-a-nodejs-project)[Step 3: install TypeScript and `@types/node`](#step-3-install-typescript-and-typesnode)[Step 4: initialize a TypeScript project](#step-4-initialize-a-typescript-project)[Step 5: create a TypeScript file](#step-5-create-a-typescript-file)[Step 6: example code](#step-6-example-code)[Step 7: run the TypeScript file](#step-7-run-the-typescript-file)[Conclusion](#conclusion)[References](#references)

## [Introduction](#introduction)

In this post, I will show you how to run TypeScript without compiling it to JavaScript first. This is useful for debugging and testing.

## [Set up a TypeScript project](#set-up-a-typescript-project)

### [Step 1: create a directory](#step-1-create-a-directory)

Create a directory for the project.

Terminal window

```
1# Create a directory2mkdir run-typescript-without-compiling3
4# Change directory5cd run-typescript-without-compiling
```

### [Step 2: initialize a Node.js project](#step-2-initialize-a-nodejs-project)

Initialize a Node.js project.

Terminal window

```
1# Initialize a Node.js project2yarn init -y
```

### [Step 3: install TypeScript and `@types/node`](#step-3-install-typescript-and-typesnode)

Install TypeScript and `@types/node`.

Terminal window

```
1# Install TypeScript and @types/node2yarn add -D typescript @types/node
```

### [Step 4: initialize a TypeScript project](#step-4-initialize-a-typescript-project)

Initialize a TypeScript project.

Terminal window

```
1# Initialize a TypeScript project2yarn tsc --init
```

### [Step 5: create a TypeScript file](#step-5-create-a-typescript-file)

Create a TypeScript file.

Terminal window

```
1# Create a src directory2mkdir src3
4# Create a TypeScript file5touch src/index.ts
```

### [Step 6: example code](#step-6-example-code)

Add the following code to the TypeScript file.

src/index.ts

```
1const sum = (a: number, b: number): number => a + b;2const subtract = (a: number, b: number): number => a - b;3const multiply = (a: number, b: number): number => a * b;4const divide = (a: number, b: number): number => a / b;5
6console.log(sum(1, 2));7console.log(subtract(1, 2));8console.log(multiply(1, 2));9console.log(divide(1, 2));
```

### [Step 7: run the TypeScript file](#step-7-run-the-typescript-file)

Now, we will install `ts-node` and run the TypeScript file.

Terminal window

```
1# Install ts-node2yarn add -D ts-node
```

Add the following code to the `package.json` file.

package.json

```
1{2  ...3  "scripts": {4    "playground": "ts-node src/index.ts",5    "playground:watch": "nodemon -e ts -w . -x esr src/index.ts",6    "build": "tsc",7    "build:watch": "tsc -w",8    "build:debug": "tsc --sourceMap",9    "build:debug:watch": "tsc -w --sourceMap",10    "start": "node dist/index.js",11    "start:watch": "nodemon -e js -w dist -x esr dist/index.js"12  },13  ...14}
```

  

Note

`nodemon` is a utility that will monitor for any changes in your source and automatically restart your server. You can install it using `yarn global add nodemon` or `npm install -g nodemon`.

Run the TypeScript file.

Terminal window

```
1# Run the TypeScript file2yarn playground3
4# Output536-17280.5
```

## [Conclusion](#conclusion)

In this post, I showed how to run TypeScript without first converting it to JavaScript. For testing and troubleshooting, that is helpful.

## [References](#references)

-   [TypeScript Official Website](https://www.typescriptlang.org/)
-   [TypeScript Documentation](https://www.typescriptlang.org/docs/)
-   [ts-node on npm](https://www.npmjs.com/package/ts-node)
-   [ts-node GitHub Repository (TypeStrong/ts-node)](https://github.com/TypeStrong/ts-node)
-   [nodemon on npm](https://www.npmjs.com/package/nodemon)
-   [nodemon Official Website](https://nodemon.io/)
-   [Node.js Official Website](https://nodejs.org/)
-   [Node.js Documentation](https://nodejs.org/en/docs/)
-   [Yarn Package Manager](https://yarnpkg.com/)
-   [TypeScript `tsconfig.json` Reference](https://www.typescriptlang.org/tsconfig)
-   [npm `package.json` Guide](https://docs.npmjs.com/cli/v7/configuring-npm/package-json)
-   [`@types/node` package on npm](https://www.npmjs.com/package/@types/node) (for Node.js type definitions)
-   [TypeScript Playground](https://www.typescriptlang.org/play) (for quick experiments)

Was this useful?

## Tags

[#TypeScript](/blog/tags/typescript)[#Node.js](/blog/tags/nodejs)[#Ts node](/blog/tags/ts-node)[#Nodemon](/blog/tags/nodemon)[#JavaScript](/blog/tags/javascript)[#Development Workflow](/blog/tags/development-workflow)[#Debugging](/blog/tags/debugging)[#Testing](/blog/tags/testing)[#TypeScript Execution](/blog/tags/typescript-execution)

## Share

[Facebook](https://facebook.com/sharer/sharer.php?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling "Share on Facebook")[Twitter](https://twitter.com/intent/tweet/?text=Run%20TypeScript%20Without%20Compiling&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling "Share on Twitter")[LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling&title=Run%20TypeScript%20Without%20Compiling&summary=We%20can%20run%20TypeScript%20without%20compiling%20it%20to%20JavaScript.%20This%20is%20useful%20for%20debugging%20and%20testing.%20In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20do%20it.&source=https://mkabumattar.com "Share on LinkedIn")[WhatsApp](https://wa.me/?text=Run%20TypeScript%20Without%20Compiling%20https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling "Share on WhatsApp")[Telegram](https://t.me/share/url?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling&text=Run%20TypeScript%20Without%20Compiling "Share on Telegram")[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling&title=Run%20TypeScript%20Without%20Compiling "Share on Reddit")[Hacker News](http://news.ycombinator.com/submitlink?u=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling&t=Run%20TypeScript%20Without%20Compiling "Share on Hacker News")[Pinterest](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling&media=&description=We%20can%20run%20TypeScript%20without%20compiling%20it%20to%20JavaScript.%20This%20is%20useful%20for%20debugging%20and%20testing.%20In%20this%20post%2C%20I%20will%20show%20you%20how%20to%20do%20it. "Share on Pinterest")[Email](<mailto:?subject=Run%20TypeScript%20Without%20Compiling&body=Check out this article: https%3A%2F%2Fmkabumattar.com%2Fblog%2Fpost%2Frun-typescript-without-compiling>)

## Comments

## You might also enjoy

More posts on similar topics

[![TypeScript vs. JSDoc: Static Type Checking in JavaScript Compared](/_astro/hero.DqNoDaeT_2oupii.webp)](/blog/post/typescript-vs-jsdoc-exploring-the-pros-and-cons-of-static-type-checking-in-javascript)

## [TypeScript vs. JSDoc: Static Type Checking in JavaScript Compared](/blog/post/typescript-vs-jsdoc-exploring-the-pros-and-cons-of-static-type-checking-in-javascript)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [JavaScript](/blog/categories/javascript)
-   [TypeScript](/blog/categories/typescript)
-   [Static Typing](/blog/categories/static-typing)
-   [Development Tools](/blog/categories/development-tools)
-   [Code Quality](/blog/categories/code-quality)

TL;DRTypeScript and JSDoc are two tools for static type checking in JavaScript. TypeScript offers a full type system, advanced features, and strict type checking. JSDoc provides lightweight

[#TypeScript](/blog/tags/typescript)[#JSDoc](/blog/tags/jsdoc)[#Static Type Checking](/blog/tags/static-type-checking)+4 tags

[read more](/blog/post/typescript-vs-jsdoc-exploring-the-pros-and-cons-of-static-type-checking-in-javascript)

[![Setting up Node.js, Express, Prettier, ESLint, and Husky application with Babel and TypeScript - Part 1](/_astro/hero.DKzl3k6w_w3X8j.webp)](/blog/post/setting-up-node-js-express-prettier-eslint-and-husky-application-with-babel-and-typescript-part-1)

## [Setting up Node.js, Express, Prettier, ESLint, and Husky application with Babel and TypeScript - Part 1](/blog/post/setting-up-node-js-express-prettier-eslint-and-husky-application-with-babel-and-typescript-part-1)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Node.js](/blog/categories/nodejs)
-   [TypeScript](/blog/categories/typescript)
-   [Development Setup](/blog/categories/development-setup)
-   [JavaScript Tooling](/blog/categories/javascript-tooling)

Introduction All code from this tutorial as a complete package is available in this repos

[#Node.js](/blog/tags/nodejs)[#Express.js](/blog/tags/expressjs)[#TypeScript](/blog/tags/typescript)+9 tags

[read more](/blog/post/setting-up-node-js-express-prettier-eslint-and-husky-application-with-babel-and-typescript-part-1)

[![Setting up Node JS, Express, MongoDB, Prettier, ESLint and Husky Application with Babel and authentication as an example](/_astro/hero.C-0XrT7F_1bXKFs.webp)](/blog/post/setting-up-node-js-express-mongodb-prettier-eslint-and-husky-application-with-babel-and-authentication-as-an-example)

## [Setting up Node JS, Express, MongoDB, Prettier, ESLint and Husky Application with Babel and authentication as an example](/blog/post/setting-up-node-js-express-mongodb-prettier-eslint-and-husky-application-with-babel-and-authentication-as-an-example)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Node.js](/blog/categories/nodejs)
-   [JavaScript](/blog/categories/javascript)
-   [Development Setup](/blog/categories/development-setup)
-   [API Development](/blog/categories/api-development)

Introduction All code from this tutorial as a complete package is available in this repository. If you find this tutorial helpful, please share i

[#Node.js](/blog/tags/nodejs)[#Express.js](/blog/tags/expressjs)[#MongoDB](/blog/tags/mongodb)+11 tags

[read more](/blog/post/setting-up-node-js-express-mongodb-prettier-eslint-and-husky-application-with-babel-and-authentication-as-an-example)

[![The ORM Dilemma: To Use or Not to Use](/_astro/hero.DwvXnAvK_Zoy6I4.webp)](/blog/post/why-not-to-use-orm-in-nodejs)

## [The ORM Dilemma: To Use or Not to Use](/blog/post/why-not-to-use-orm-in-nodejs)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Node.js](/blog/categories/nodejs)
-   [Database Management](/blog/categories/database-management)
-   [Software Architecture](/blog/categories/software-architecture)
-   [TypeScript](/blog/categories/typescript)

Introduction Some decisions shape a project more than others. One that keeps coming back is whether to use an Object-Relational Mapping (ORM) tool for database interactions. Should you skip an ORM

[#ORM](/blog/tags/orm)[#Node.js](/blog/tags/nodejs)[#TypeScript](/blog/tags/typescript)+8 tags

[read more](/blog/post/why-not-to-use-orm-in-nodejs)

[![React Context API for State Management](/_astro/hero.Dv7VXd7h_Z4sE61.webp)](/blog/post/react-context-api-state-management)

## [React Context API for State Management](/blog/post/react-context-api-state-management)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [ReactJS](/blog/categories/reactjs)
-   [State Management](/blog/categories/state-management)
-   [Frontend Development](/blog/categories/frontend-development)
-   [Next.js](/blog/categories/nextjs)
-   [JavaScript](/blog/categories/javascript)

Introduction Managing application state well can make or break a React project. React offers several options for state management, and the Context API is one of the most flexible. But what exactly

[#React Context API](/blog/tags/react-context-api)[#State Management](/blog/tags/state-management)[#Redux](/blog/tags/redux)+7 tags

[read more](/blog/post/react-context-api-state-management)

[![Setting up JWT Authentication in TypeScript with Express, MongoDB, Babel, Prettier, ESLint, and Husky - Part 2](/_astro/hero.DKzl3k6w_w3X8j.webp)](/blog/post/setting-up-jwt-authentication-in-typescript-with-express-mongodb-babel-prettier-eslint-and-husky-part-2)

## [Setting up JWT Authentication in TypeScript with Express, MongoDB, Babel, Prettier, ESLint, and Husky - Part 2](/blog/post/setting-up-jwt-authentication-in-typescript-with-express-mongodb-babel-prettier-eslint-and-husky-part-2)

-   [Mohammad Abu Mattar](/authors/mohammad-abu-mattar)
-   [Backend Development](/blog/categories/backend-development)
-   [Node.js](/blog/categories/nodejs)
-   [TypeScript](/blog/categories/typescript)
-   [Authentication](/blog/categories/authentication)
-   [API Development](/blog/categories/api-development)

Introduction Why do we even need an authentication mechanism in an application? In my opinion, it doesn't need to be explained. The phrases authentication and authorization have likely crossed you

[#JWT](/blog/tags/jwt)[#Express.js](/blog/tags/expressjs)[#MongoDB](/blog/tags/mongodb)+10 tags

[read more](/blog/post/setting-up-jwt-authentication-in-typescript-with-express-mongodb-babel-prettier-eslint-and-husky-part-2)

6 related posts
