Node.js安裝與配置

來源:互聯網
上載者:User

Node.js是一套用來編寫高效能網路伺服器的JavaScript工具包,一系列的變化由此開始。比較獨特的是,Node.js會假設在POSIX環境下運行Linux 或 Mac OS X。如果是在Windows下,那就需要安裝MinGW以獲得一個仿POSIX的環境。在Node中,Http是首要的。Node為建立http伺服器作了最佳化,所以在網上看到的大部分樣本和庫都是集中在web上。

本文只是node.js的簡單安裝與配置,注意此版本的nodejs安裝python2.7

安裝python2.7

1.去官網下載python2.7

http://python.org

2.解壓與編譯

tar xvf Python-2.7.5.tar.bz2

cd Python-2.7.5

./configure --prefix=/usr/local/python2.7

make&&make install

ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7 #做一個連結,或者吧/usr/local/python2.7/bin/加到PATH變數中

1.去官網下載nodejs v0.10.7安裝包,注意選擇INSTALL

2.解壓與編譯

tar xvf node-v0.10.7.tar.gz

cd node-v0.10.7

./configure

make&&make install

3.編寫一個js檔案

#vim test.js

var http = require('http');


http.createServer(function (req, res) {

  res.writeHead(200, {'Content-Type': 'text/plain'});

  res.end('Hello World\n');

}).listen(8080, "127.0.0.1");

console.log('Server running at http://127.0.0.1:8080/');

node test.js & #後台運行

4.訪問

elinks http://127.0.0.1:8080/

這時候應該就可以看到hello world了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.