You need to enable JavaScript to run this app.

Ana içeriğe geç

Yazar:    KodlarTR Tarih: 05-16-2025, 08:13 PM
Node.js ile web sunucusu nasıl oluşturulur?

Cevap: Node.js’nin yerleşik http modülü veya Express.js gibi framework’ler kullanılarak web sunucusu oluşturulabilir.

Örnek Kod (Basit HTTP Sunucusu):
javascript

Kopyala
Kod:
const http = require('http');
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Merhaba, Node.js!');
});
server.listen(3000, () => console.log('Sunucu 3000 portunda çalışıyor'));


Express.js ile Örnek:
javascript

Kopyala
Kod:
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Merhaba, Express!'));
app.listen(3000, () => console.log('Sunucu 3000 portunda'));