「Node.js/基本範例程式」修訂間的差異
跳至導覽
跳至搜尋
(新頁面: 分類:Node.js) |
|||
| 第1行: | 第1行: | ||
[[分類:Node.js]] | [[分類:Node.js]] | ||
| + | |||
| + | |||
| + | ===一、示例一=== | ||
| + | <pre>// 引入 Node.js 的核心模組 | ||
| + | const http = require('http'); | ||
| + | |||
| + | // 建立一個 HTTP 伺服器 | ||
| + | const server = http.createServer((req, res) => { | ||
| + | // 設定 HTTP 回應的狀態碼、標頭和內容 | ||
| + | res.statusCode = 200; | ||
| + | res.setHeader('Content-Type', 'text/plain'); | ||
| + | res.end('Hello, World!\n'); | ||
| + | });</pre> | ||
於 2023年2月14日 (二) 10:55 的修訂
一、示例一
// 引入 Node.js 的核心模組
const http = require('http');
// 建立一個 HTTP 伺服器
const server = http.createServer((req, res) => {
// 設定 HTTP 回應的狀態碼、標頭和內容
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, World!\n');
});