Installing TypeScript in Node.js Projects: Express Server Development Step by Step
🧠 What Will You Learn in This Guide?
In this guide, you will learn step by step how to set up a type-safe project using TypeScript on Node.js.
In the following steps, you will see how to integrate the Express framework, improve code quality with ESLint, and configure the tsconfig.json file.
Steps to Follow:
- Starting the project directory (
npm init) - TypeScript installation and compiler configuration
- Adding express and type definitions
- Writing TypeScript server code
- Compiling (
npx tsc) and running - Code inspection with ESLint
- Editing package.json scripts
1️⃣ Creating and Launching the Project Directory
Create a new folder and start npm project:
mkdir genixnode-node-ts
cd genixnode-node-ts
npm init -y
💡 Description: The -y parameter creates the package.json file, answering all questions by default.
2️⃣ Configuring the TypeScript Compiler
Install TypeScript as a development dependency:
npm install --save-dev typescript
Now create the tsconfig.json file containing the compiler settings:
npx tsc --init
Apply the following settings:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2020",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"strict": true
},
"lib": ["es2020"]
}
📘 Summary:
"module": "commonjs" → Node.js module system
"outDir": "dist" → Output of compiled files
"strict": true" → Strict type checking
"esModuleInterop": true" → ES module compatibility
3️⃣ Installing Express Server and Type Definitions
Add the Express framework to the project:
npm install express
npm install --save-dev @types/express
📘 Description: @types/express adds TypeScript type information for the Express library.
Create your source folder:
mkdir src
nano src/app.ts
Add the following code to app.ts file 👇
import express, { Request, Response } from 'express';
const app = express();
const port = 3000;
const sunucuAdresi = 'tr1-node01.ornek.com';
app.get('/', (req: Request, res: Response) => {
res.send('GenixNode Hoş Geldiniz!');
});
app.listen(port, () => {
console.log(`Sunucu aktif: http://${sunucuAdresi}:${port}`);
});
💡 This code creates an Express server running on port 3000.
4️⃣ Compiling and Running TypeScript Code
Convert the code to JavaScript:
npx tsc
💬 Description: This command compiles the src/app.ts file and produces dist/app.js output.
Start the server:
node dist/app.js
🟢 Expected output:
Sunucu aktif: http://tr1-node01.ornek.com:3000
5️⃣ Code Quality Control with ESLint
Install ESLint to maintain code consistency:
npm install --save-dev eslint
npm init @eslint/config@latest
Kurulum sırasında şu seçenekleri belirleyin:
Kullanım amacı: Sözdizimi kontrolü ve hata bulma
Modül tipi: JavaScript modules (import/export)
Framework: None
TypeScript kullanımı: Yes
Çalışma ortamı: Node
Config dosyası formatı: JavaScript
Yapılandırmadan sonra .eslintrc.js dosyanız şöyle görünmelidir:
module.exports = {
env: {
es2021: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 13,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {},
};
Check your code:
npx eslint . --ext .ts
6️⃣ Updating package.json Commands
Add frequently used commands to your package.json file:
"scripts": {
"start": "tsc && node dist/app.js",
"lint": "eslint . --ext .ts",
"test": "echo \"Error: no test specified\" && exit 1"
}
You can now use the following shortcuts:
npm run start # Derle ve çalıştır
npm run lint # Kod denetimi yap
🧩 Useful Settings (for tsconfig.json)
| ⚙️ Setting | 💬 Description | 💡 Recommended Value |
|---|---|---|
"strict" | It detects type errors early. | true |
"rootDir" | Directory of TypeScript source files. | "./src" |
"outDir" | Output of compiled JavaScript files. | "./dist" |
"skipLibCheck" | The library speeds up type checking. | true |
❓ Frequently Asked Questions (FAQ)
- Does using TypeScript reduce Node.js performance?
No. TypeScript only runs during compilation. At runtime, Node.js runs pure JavaScript code.
- Why is the @types/express package needed?
Express is written in JavaScript. This package enables TypeScript to recognize the Express API.
- Is constantly compiling tiring?
Yes, so you can use ts-node:
npx ts-node src/app.ts
- What is the most important setting in tsconfig.json?
Absolutely "strict": true. Maximizes code security.
- Why is ESLint important?
It preserves code style and detects possible errors early. Provides standardization in team projects.
🚀 Result
With this guide:
We configured TypeScript on Node.js,
We set up a server with Express,
We increased the code quality with ESLint,
We automated the project with npm scripts.
Now you are ready to develop type-safe, modern and scalable Node.js projects. You can immediately run your application on the powerful virtual servers of the GenixNode platform and scale it safely. ☁️

