一、 安裝Python
從以下地址下載并安裝Python2.7.10(Windows)安裝程序:
https://www.python.org/downloads/
ADD TO PATH選項
二、 安裝NODE.JS
從以下地址下載并安裝node.js(Windows)安裝程序:
https://nodejs.org/
ADD TO PATH選項
Current Version: v5.0.0
安裝路徑:D:\nodejs
三、 配置NODE.JS
進入命令行模式,將當前目錄切換至:D:\nodejs
node -v
node -h
node help install
npm的包安裝分為本地安裝(local)、全局安裝(global)兩種,從敲的命令行來看,差別只是有沒有-g而已:
本地安裝
1. 將安裝包放在 ./node_modules 下(運行npm時所在的目錄)
2. 可以通過 require() 來引入本地安裝的包
全局安裝
1. 將安裝包放在 /usr/local 下
2. 可以直接在命令行里使用
設置全局目錄:
npm config set prefix "D:\nodejs"
設置Cache目錄:
(先建好cache目錄)
npm config set cache "D:\nodejs\cache"
Taobao鏡像:
npm install cnpm --registry=https://registry.npm.taobao.org -g
如果使用taobao鏡像安裝,可以使用cnpm命令替代npm命令
也可以將默認資料庫通過以下命令改為:
npm config set registry https://registry.npm.taobao.org
NPM中國鏡像:
npm config set registry http://registry.cnpmjs.org
npm --registry http://registry.cnpmjs.org
四、 安裝常用模塊
到哪去找我需要的模塊,有個網站必須提一下,http://search.npmjs.org/
--編譯模塊
npm install node-gyp -g
npm install gyp -g
--nw.js
npm install nw -g
--其他模塊
npm install cordova -g
npm install phonegap –g
npm install socket.io –g
npm install express -g
npm install ffi ref –g
五、 測試程序
寫一段簡短的代碼,保存為helloworld.js,大致看下nodejs是怎么用的。
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.end();
}).listen(8080);
console.log("Server running at http://localhost:8080/");
打開命令行,轉到當前文件所存放的路徑下,運行 node hello.js命令即可
如果一切正常,可以看到命令行輸出:Server running at http://localhost:8080/
同時,在瀏覽器輸入http://localhost:8080/,可以看到一個寫著helloworld的網頁。