標籤:模板引擎 地址 ade function oam express 自己 nbsp tor
1、安裝nodejs,比如安裝在E:\program files\nodejs(這是本人的安裝路徑)。
確保有兩個環境變數
使用者環境變數:C:\Users\Administrator\AppData\Roaming\npm
系統內容變數:e:\program files\nodejs
2、安裝Express,用穩定版3.5.0,網上資料也大多以這個版本為主,不指定版本的話,預設安裝最新版
運行cmd -> npm install -g [email protected]
如果是4.X版本,再安裝npm install -g express-generator(如果不裝會報”express“是外部命令)
3、express安裝成功後,可以用命令列建立一個測試app
運行cmd -> express myapp
4、將相依模組拷貝到myapp的根目錄,
可以手動拷貝:將 e:\program files\nodejs\node_global\node_modules下面的express目錄拷貝到應用根目錄(親測)
也可以執行命令:cmd -> cd e:\program files\nodejs\myapp ->npm install
5、安裝模板引擎jade,將jade安裝到當前建立的應用下面
運行cmd -> cd e:\program files\nodejs\myapp -> npm install jade
6、啟動myapp,預設url:http://localhost:3000
運行cmd -> cd e:\nodejs\myqpp -> npm start或者node test.js
test.js 內容為
var http=require("http");
http.createServer(function(req,res){
res.writeHead(200,{"Content-Type":"text/html"});
res.write("<h1>Node.js</h1>");
res.write("<P>Hello World</p>");
res.end("<p>beyondweb.cn</p>");
}).listen(9999);
console.log("nodejs start listen at port 9999.");
7、在瀏覽器訪問 開啟地址http://127.0.0.1:9999/,顯示歡迎頁面
nodejs+express+jade配置