使用ExpressJS:如何使用app.use提供静态文件与app.get()?

时间:2017-12-01 21:58:58

标签: express

我正在使用express来提供文件,一切正常,但我无法将我的console.log语句显示在app.get()route statment中。我目前正在使用app.use(express.static("public"));从公共文件夹中提供服务。

以下是完整代码:

//Server static files from the public folder.
app.use(express.static("public"));

app.listen(PORT, function(){
console.log("Sever is running and listening on port: " +PORT);
});

//Establish routes
app.get('/', function (req, res) {
//res.sendFile('/student-profile');
res.send("This is the response.");
});

1)我怎样才能完成这项工作?

2)另外,index.html是从公用文件夹提供静态文件时要查找的第一个文件吗?

0 个答案:

没有答案