Hello World
打開你最喜歡的編輯器,創建一個helloworld.js文件,輸入console.log("Hello World");後保存
打開Node.js的CMD窗口,將文件拖拽到窗口中,輸入node js文件路徑
Http版Hello World
編寫 helloworld.js 代碼如下:
[JavaScript]
var http = require('http');
server = http.createServer(function (req, res) {
res.writeHeader(200, {"Content-Type": "text/plain"});
res.end("Hello World\n");
})
server.listen(8000);
console.log("httpd start @8000");
運行 node helloworld.js按照上面node.js cmd的方法,控制臺顯示 httpd start @8000