| Throttle Fonksiyonu | ```js
function throttle(fn,limit){let wait=false;return(...a)=>{if(!wait){fn(...a);wait=true;setTimeout(()=>wait=false,limit);}}}
``` | Performans için limite çeker. |
| Cookie Oku | `document.cookie` | Basit cookie görüntüleme. |
| URL Param Okuma | `new URLSearchParams(location.search)` | ?id= gibi parametreleri okur. |
---
## **3️⃣ Node.js Temel Scriptleri**
| **Script Türü** | **Kod** | **Ne İşe Yarar?** |
|-----------------|----------|--------------------|
| Server Oluşturma | ```js
const http=require('http');
http.createServer((req,res)=>res.end("OK")).listen(3000);
``` | Basit HTTP sunucusu başlatır. |
| JSON Okuma | ```js
const data=require('./data.json');
``` | JSON dosyasını direkt import eder. |
| Modül Oluşturma | ```js
module.exports = { fn(){} }
``` | Fonksiyon/dosya export eder. |
| Çevresel Değişken | `process.env.KEY` | .env içeriğine erişim. |
---
## **4️⃣ Node.js File System (FS) Scriptleri**
| **Konu** | **Kod** | **Açıklama** |
|----------|----------|--------------|
| Dosya Okuma | ```js
const fs=require('fs');
fs.readFileSync('dosya.txt','utf8');
``` | Dosya içerik okuma. |
| Dosya Yazma | ```js
fs.writeFileSync('log.txt','Merhaba');
``` | Dosya oluşturur/yazar. |
| Klasör Listeleme | ```js
fs.readdirSync('./');
``` | Klasördeki dosyaları listeler. |
| Akış (Stream) Okuma | ```js
fs.createReadStream('file');
``` | Büyük dosyalarda performans sağlar. |
---
## **5️⃣ Express.js Backend Scriptleri**
| **Konu** | **Kod** | **Açıklama** |
|----------|---------|--------------|
| Express Server | ```js
const express=require('express');
const app=express();
app.get('/',(req,res)=>res.send("OK"));
app.listen(3000);
``` | REST API temeli. |
| JSON Body Parse | `app.use(express.json())` | API gövdelerini işler. |
| Route Param | `app.get('/user/:id')` | /user/12 gibi dinamik URL. |
| Middleware | ```js
app.use((req,res,next)=>{console.log(req.url);next();});
``` | Tüm istekleri loglar. |
---
## **6️⃣ Node.js Asenkron Programlama Scriptleri**
| **Script** | **Kod** | **Ne İçin Kullanılır?** |
|------------|----------|-------------------------|
| Promise | ```js
new Promise((res)=>res(123))
``` | Async kontrol mekanizması. |
| Async/Await | ```js
async function run(){ return await fetch(url); }
``` | Okunabilir async kod yazma. |
| Paralel Çalıştırma | ```js
await Promise.all([f1(),f2()]);
``` | Çoklu işlemi aynı anda çalıştırır. |
---
## **7️⃣ Node.js Veri İşleme Scriptleri**
| **Konu** | **Kod** | **Açıklama** |
|----------|----------|--------------|
| CSV Okuma | `csv-parser` modülü | CSV içeriğini objeye dönüştürür. |
| Hash Üretimi | ```js
const crypto=require('crypto');
crypto.createHash('sha256').update("data").digest('hex');
``` | SHA-256 üretir. |
| JWT Üretme | `jwt.sign(payload,key)` | Token oluşturma. |
| Rate Limit | `express-rate-limit` | API saldırılarına karşı koruma. |
---
## **8️⃣ Güvenlik & Loglama Scriptleri**
*(Tamamen LEGAL, savunma amaçlıdır.)*
| **Script** | **Kod** | **Açıklama** |
|------------|---------|--------------|
| IP Loglama | ```js
app.use((req,res,next)=>{console.log(req.ip);next();})
``` | Gelen istekleri kaydeder. |
| Request Filter | ```js
if(req.headers['user-agent']=="") { block... }
``` | Bot analizlerinde kullanılır. |
| Helmet Güvenlik | `app.use(require('helmet')())` | HTTP güvenlik başlıkları ekler. |
| Rate Limit | `app.use(limiter)` | API flood koruması sağlar. |
---