Linux(centos6.0)下安装Node.js以及使用
生活随笔
收集整理的這篇文章主要介紹了
Linux(centos6.0)下安装Node.js以及使用
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Linux下(centos6.0)安裝Node.js
1.wget?http://nodejs.org/dist/node-v0.6.9.tar.gz??? tar? zxvf node-v0.6.9.tar.gz
?? cd node-v0.6.9?
?? ./configure --prefix=/usr/local/node? ----------安裝提示------------- Checking for program g++ or c++ ? ? ? ? ?: not found?
Checking for program icpc ? ? ? ? ? ? ? ?: not found?
Checking for program c++ ? ? ? ? ? ? ? ? : not found ---------------------------- yum install gcc-c++ ? 可以解決
-----------------------------
?? make
?? make install
2.測(cè)試
?? 創(chuàng)建test.js文件,內(nèi)容如下:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
執(zhí)行:node test.js
# /usr/local/node/bin/node ?/www/test.js
在瀏覽器里輸入 http://127.0.0.1:1337/,可以看到 "Hello World"字樣,即表示安裝成功!注意后面不能加文件名.
注意事項(xiàng):
1.客戶端只能通過(guò)端口訪問(wèn),不能指定js文件名.
2.監(jiān)聽(tīng)I(yíng)P地址可以省略,這樣任何地方都可以訪問(wèn).如果指定了127.0.0.1,則只能在本機(jī)才可以訪問(wèn)!
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, "192.168.1.100");
console.log('Server running at http://192.168.1.100:80/'); -------------------------------------------
注意,如果你想要要輸出 html 代碼到瀏覽器,請(qǐng)?jiān)O(shè)置 content-type 為 text/html ,如果設(shè)置為 text/plain 將只輸出文本
response.writeHead(200, {"Content-Type": "text/html;chartset:utf-8"});
-------------------------------------------- 參考: http://www.cnblogs.com/rubylouvre/archive/2010/07/15/1778403.html http://www.cnodejs.org/ http://club.cnodejs.org/topic/4f16442ccae1f4aa27001071總結(jié)
以上是生活随笔為你收集整理的Linux(centos6.0)下安装Node.js以及使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JavaScript跨域总结与解决办
- 下一篇: “耳目减聪明”下一句是什么