Node.js 是伺服器端 JavaScript 的入門好選擇。從最簡單的命令列輸出開始,再逐步建立 HTTP 服務,可以很快掌握基本流程。

var sys = require("sys");
sys.puts("Hello world");在命令列執行 node hello.js,即可看到輸出。
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/html" });
response.write("Hello World!");
response.end();
}).listen(8080);啟動後,用瀏覽器訪問 https://localhost:8080/,就能看到 Hello World。


Node.js 提供 Buffer 類別,可用於處理二進位資料與字串編碼。常見編碼包含 ascii、utf8 與 binary。
這些範例看似簡單,卻已涵蓋 Node.js 最基本的執行方式、模組載入、HTTP 回應與資料處理概念。