【发布时间】:2017-12-01 21:58:58
【问题描述】:
我正在使用 express 来提供文件并且一切正常,但我无法让我的 console.log 语句显示在 app.get() 路由语句中。我目前使用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 是否是第一个查找的文件?
【问题讨论】:
-
你是进口快递吗?例如:
const express = require('express'); const app = express();? -
是的,它们已被导出。
-
我发现在使用
express.static('public');时不需要app.get('/')但是,对于任何POST 请求,您都需要一个post route 方法。
标签: express