<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Title</titel>
</head>
<body>
<p>中間件</p>
</body>
var http=require("http");
var express = require("express");
var app = express();
//自定義中間件
//中間件是按順序執行,如果沒有用到next,則會停止
app.use("/",function(req,res,next){
console.log("進入自定義中間件");
next();
});
//傳入public,能訪問到靜態頁面,express.static爲express自帶中間件
app.use("/",express.static(__dirname+"/public"))
console.log("hello server")
res.send("hello browser!");
res.end();
})
if(err){
console.log("服務器錯誤")
}else{
console.log("服務器啓動成功,監聽3000端口")
}
})