【发布时间】:2021-03-04 00:29:15
【问题描述】:
我知道网站上有很多这样的问题,但我已经在这个网站上尽我所能,我能在 heroku 上工作的最好方法是在浏览器上显示一个文本,我一直在努力解决这个问题现在代码2天,没有成功,下面是我的目录布局。 image of my directory structure
下面是我的代码
app.use(express.static(__dirname + "/public/"));
app.get("/", (req, res, next) => {
res.sendFile(path.join(__dirname + "public", 'index.html'));
//res.send('Testing one two');
});
const port = process.env.PORT || '5000';
app.listen(port, () => console.log("Server running on port 5000"));
当我在我的机器上运行此代码时,它运行良好,实际上有近 5 种方法可以更改代码,它仍然可以在我的机器上运行,但不能在 heroku 上运行,我让 horoku 工作的最好方法是只是为了显示一个文本。我需要如何使这项工作,现在已经超过 2 天了,我什至不明白错误消息中找不到目录
【问题讨论】:
标签: javascript node.js express heroku