歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Node.js安裝與配置

Node.js安裝與配置

日期:2017/2/28 14:48:18   编辑:Linux教程

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了

更多關於Node.js的詳細信息,或者下載地址請點這裡

Copyright © Linux教程網 All Rights Reserved