为什么express.static不为我的公用文件夹提供服务



我试图为我的公用文件夹提供服务,但我不知道为什么我的express.static线路不工作。

这就是我的公用文件夹的样子:

public
-images
---img1.png
---blah.png
-js
---app.js
-pages
---index.html
---blah.html
---blah.html
-styles
---styles.css
我的代码如下所示:
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static("public"));
app.listen(PORT, () => {
console.log(`Server running on port: ${PORT}`);
});

试试这个:

const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
let app = express();
app.use(express.static("public"));
app.listen(PORT, () => {
console.log(`Server running on port: ${PORT}`);
});

你需要将express((分配给应用程序,它才能像我一样工作。如果答案有效,请接受,谢谢:(。

最新更新