Node.js 和 Heroku 错误:Web 进程在启动后 60 秒内无法绑定到 $PORT
Posted
技术标签:
【中文标题】Node.js 和 Heroku 错误:Web 进程在启动后 60 秒内无法绑定到 $PORT【英文标题】:Node.js and Heroku error: Web process failed to bind to $PORT within 60 seconds of launch 【发布时间】:2021-02-19 21:28:59 【问题描述】:我一直在尝试使用heroku
制作机器人,但在部署它时出现此错误:Web process failed to bind to $PORT within 60 seconds of launch
。
我做了很多事情,包括尝试app.listen(process.env.PORT || 5000)
,但我收到了错误app is not defined
。
这是我的 index.js:
const discord = require('discord.js');
const bot = new discord.Client();
const token = 'Nzc0MjQxOTAyMzE2MjI0NTIy.X6U69g.sjmAievx3II561tvYfOVy72an1k';
bot.on('ready', () =>
console.log('This bot is online');
)
bot.on('message', message=>
if(message.content === "im lost")
message.channel.send('You should try finding your way through the welcome channel!')
if(message.content === "i need help")
message.channel.send('Check out the bot-help channel!')
)
bot.login(token);
package.json:
"name": "compass",
"version": "1.0.0",
"main": "index.js",
"scripts":
"start": "node index.js"
,
"author": "Alex",
"license": "ISC",
"dependencies":
"discord.js": "^12.4.1",
"express": "^4.17.1"
,
"devDependencies": ,
"repository":
"type": "git",
"url": "git+https://github.com/Razdoll/Compass-Host.git"
,
"keywords": [],
"bugs":
"url": "https://github.com/Razdoll/Compass-Host/issues"
,
"homepage": "https://github.com/Razdoll/Compass-Host#readme",
"description": ""
还有heroku日志:
2020-11-07T10:13:06.345403+00:00 heroku[web.1]: State changed from crashed to starting
2020-11-07T10:13:06.144839+00:00 app[api]: Deploy e1a7636b by user alexismastakouris08@gmail.com
2020-11-07T10:13:06.144839+00:00 app[api]: Release v18 created by user alexismastakouris08@gmail.com
2020-11-07T10:13:06.000000+00:00 app[api]: Build succeeded
2020-11-07T10:13:08.924332+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-07T10:13:11.837311+00:00 app[web.1]:
2020-11-07T10:13:11.837349+00:00 app[web.1]: > compass@1.0.0 start /app
2020-11-07T10:13:11.837349+00:00 app[web.1]: > node index.js
2020-11-07T10:13:11.837350+00:00 app[web.1]:
2020-11-07T10:13:12.713528+00:00 app[web.1]: This bot is online
2020-11-07T10:14:09.151016+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-11-07T10:14:09.171490+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-11-07T10:14:09.269376+00:00 heroku[web.1]: Process exited with status 137
2020-11-07T10:14:09.322850+00:00 heroku[web.1]: State changed from starting to crashed
【问题讨论】:
【参考方案1】:您在 Heroku 上将其设置为 web dyno,而不是 worker dyno。 Discord 机器人是工人。
在 Heroku 应用的资源选项卡上,关闭 web dyno,然后打开一个 worker dyno。
【讨论】:
以上是关于Node.js 和 Heroku 错误:Web 进程在启动后 60 秒内无法绑定到 $PORT的主要内容,如果未能解决你的问题,请参考以下文章
在 Heroku 上部署 node.js 应用程序(discord.jd bot)导致错误
Heroku cedar 堆栈上的 Node.js 端口问题
如何在 Heroku 上使用 Node.js 通信 Web 和 Worker dynos?