node.js在Ubuntu 12.04下的安裝和配置


准備一些包
sudo apt-get install g++ curl libssl-dev apache2-utils

git是不可少的
sudo apt-get install git-core

用git下載node.js最新版
git clone git://github.com/ry/node.git

或者直接下載源碼
wget http://nodejs.org/dist/node-v0.8.2.tar.gz
gunzip node-v0.8.2.tar.gz
tar -xf node-v0.8.2

開始編譯安裝node.js
cd node-v0.8.2
./configure
make
sudo make install

輸入node –v 或者node –version可以查看node.js當前的版本

運行第一個node.js的程序
在主文件夾中創建example.js,編輯文本

var http = require('http');
  http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/'); 

 
在命令行中
Node example.js

瀏覽器中瀏覽,瀏覽器中出現hello node.js


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM