这是我在server.js文件中的设置:
const express = require('express');
const app = express();
const host = '0.0.0.0';
const PORT = process.env.PORT || 5001;
app.listen(PORT, host, () => {
console.log(`RABC Server is listening on port ${PORT}!`)
});
app.use(express.static('public'))这就是我在我的过程文件中所拥有的:
web:nodemon server.js 这是我收到的错误:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch这就是我在记录端口时得到的结果:
端口的值是:未定义
在我的package.json脚本中有:
"scripts": {
"start": "node server.js",
"build": "sanity build"
}我没有.env文件,我也不确定我是否应该有一个文件,以及里面有什么文件。
当我运行“heroku本地网络”并在本地托管时,一切都很好。
我从来没有部署或托管应用程序在我的生活,这是我的第一次。
发布于 2021-06-01 15:03:44
更新server.js到,
const express = require('express');
const app = express();
const PORT = process.env.PORT || 5001;
app.use(express.static('public'))
app.listen(PORT, () => {
console.log(`RABC Server is listening on port ${PORT}!`)
});把app.listen移到最后,
--使用逻辑和安全的初始化顺序只是惯例,在启动服务器之前首先配置它。
参考:why app.listen should be at the end after all the requests? also why is it necessary?
另外,将Procfile更新为
web:npm run starthttps://stackoverflow.com/questions/67790290
复制相似问题