1. Node.js ve TypeScript Kurulumu

VDS sunucusunda Node.js ve TypeScript’i yüklemek için şu komutları kullanın:

# Node.js kurulum

sudo apt update

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

sudo apt install -y nodejs

# TypeScript kurulum

sudo npm install -g typescript

2. Proje Yapısı

Yeni bir proje oluşturun ve gerekli bağımlılıkları yükleyin:

# Proje başlatma

npm init -y

npm install typescript ts-node @types/node --save-dev

tsconfig.json dosyasını şu şekilde oluşturun:

{

"compilerOptions": {

"target": "ES6",

"module": "commonjs",

"outDir": "./dist",

"rootDir": "./src",

"esModuleInterop": true

},

"include": ["src/**/*.ts"]

}

3. İlk TypeScript Dosyasını Yazma

src/index.ts dosyasına aşağıdaki örnek kodu ekleyin:

import http from 'http';

const server = http.createServer((req, res) => {

res.statusCode = 200;

res.end('Merhaba, VDS Sunucusundasınız!');

});

server.listen(3000, () => {

console.log('Sunucu çalışıyor');

});

4. Çalıştırma

TypeScript kodunu derleyip çalıştırın:

tsc

node dist/index.js

Alternatif olarak, ts-node kullanarak doğrudan çalıştırabilirsiniz:

npx ts-node src/index.ts

Bu adımlar, VDS sunucusunda TypeScript ile Node.js geliştirmek için temel bir başlangıçtır.

Vps.com.tr