Typescript
November 14, 2026 2 min read

Creating a TypeScript Project

HS
HEMANT SINGH
Technical Writer & Educator

Creating a TypeScript Project

Suppose we want to build a Node.js application using TypeScript.

Step 1: Create a project folder

mkdir my-typescript-project

cd my-typescript-project

Step 2: Initialize npm

npm init -y

This creates a package.json file


Step 3: Install TypeScript

npm install -D typescript

Here:

  1. npm install installs a package.
  2. -D means development dependency.
  3. TypeScript is needed during development and compilation.


Step 4: Generate tsconfig.json

npx tsc --init

This creates the TypeScript compiler configuration file.



Step 5: Create your source folder

mkdir src

Inside src, create app.ts.

and write this code.

let name: string = "Hemant";
let age: number = 32;

function greet(name: string): string {
return `Hello ${name}`;
}

console.log(greet(name));

Step 6: Compile TypeScript

npx tsc

This compiles your TypeScript files according to tsconfig.json.



Step 7: Execute JavaScript

node dist/app.js


What is package.json?


package.json is the main configuration and metadata file of an npm project.


{
"name": "my-typescript-project",
"version": "1.0.0",
"description": "My first TypeScript project",
"main": "dist/app.js",
"scripts": {
"build": "tsc",
"start": "node dist/app.js"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}

Let's understand its properties.


Property

Purpose

name

Project name

version

Project version

description

Project information

main

Package entry point

scripts

Custom commands

dependencies

Packages required at runtime

devDependencies

Packages required during development



C. What are npm scripts?

This is particularly useful.

Instead of repeatedly writing:

npx tsc

You can define a script inside package.json:

{
"scripts": {
"build": "tsc",
"start": "node dist/app.js"
}
}

Now execute:

npm run build

And:

npm start

there are some predefined commands.



Command

Explanation

npm start

scripts.start

npm test

scripts.test

npm stop

scripts.stop

npm restart

Restart lifecycle

npm run build

scripts.build

npm run dev

scripts.dev




Now install:

npm install -D typescript @types/node @types/express