一、建立一個http web服務器,並返回Hello World!node
const http = require('http'); http.createServer( (request, response) => { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n'); }).listen(8888); console.log('Server running at http://127.0.0.1:8888/');
二、啓動服務器,在瀏覽器中輸入http://127.0.0.1:8888/,頁面顯示Hello World。web
$ node example.js Server running at http://127.0.0.1:8888/