1. 程式人生 > 實用技巧 >573 http開發web伺服器

573 http開發web伺服器

什麼是Web伺服器?

當應用程式(客戶端)需要某一個資源時,可以向一個臺伺服器,通過Http請求獲取到這個資源;提供伺服器的這個伺服器,就是一個Web伺服器;

Web伺服器

目前有很多開源的Web伺服器:Nginx、Apache(靜態)、Apache Tomcat(靜態、動態)、Node.js

一. Http模板基本使用

1.1. 如何建立服務

1.1.1. Web伺服器初體驗

建立一個Web伺服器的初體驗:

const http = require('http');

const HTTP_PORT = 8000;

const server = http.createServer((req, res) => {
  res.end("Hello World");
});

server.listen(8000, () => {
  console.log(`