以ubuntu为例:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
然后用浏览器打开 http://192.168.177.71:8124/ , 应该能够看到“Hello Node.js”。
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
用node来运行这段代码:
编写第一个node.js程序,体会node.js编程和使用方法,源码如下:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "192.168.177.71");
console.log('Server running at http://192.168.177.71:8124/');
node hello_node.js
Server running at http://
192.168.177.71:8124/
然后用浏览器打开 http://192.168.177.71:8124/ , 应该能够看到“Hello Node.js”。