node應用編譯安裝
# apt-get install gcc make build-essential openssl g++ zlib1g-dev libssl-doc aptitude libssl-dev
# cd /usr/src
# wget https://nodejs.org/download/release/v4.4.6/node-v4.4.6.tar.gz
# tar -zxvf node-v4.4.6.tar.gz
# cd node-v4.4.6/
# ./configure --prefix=/Sioeye/SioApps/Environment/node
# make && make install
# vi /etc/profile.d/node
#添加以下環境變
export PATH=${JAVA_HOME}/bin:$PATH:/Sioeye/SioApps/Environment/node/bin
source /etc/profile.d/node
# 查看是否返回版本號,若是正常返回版本號,說明安裝正確
# node -v
# vim server.js
var http = require('http');//使用 require 指令來載入 http 模塊,並將實例化的 HTTP 賦值給變量 http
http.createServer(function (request, response) {
// 發送 HTTP 頭部
// HTTP 狀態值: 200 : OK
// 內容類型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 發送響應數據 "Hello World"
response.end('Hello World\n');
}).listen(8888);//使用 http.createServer()方法建立服務器,並使用listen方法綁定 8888 端口。函數經過request,response 參數來接收和響應數據。
// 終端打印以下信息
console.log('Server running at http://127.0.0.1:8888/');
# curl http://127.0.0.1:8888
Hello World