var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8888, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8888/');
然後執行
~$ node HelloWorld.js
打開瀏覽器http://127.0.0.1:8888/
就可以看到Hello World
See Also
Synopsis
Node - HTTP