【问题标题】:Node.js and Heroku error: Web process failed to bind to $PORT within 60 seconds of launchNode.js 和 Heroku 错误:Web 进程在启动后 60 秒内无法绑定到 $PORT
【发布时间】: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

【问题讨论】:

    标签: node.js heroku


    【解决方案1】:

    您在 Heroku 上将其设置为 web dyno,而不是 worker dyno。 Discord 机器人是工人。

    在 Heroku 应用的资源选项卡上,关闭 web dyno,然后打开一个 worker dyno。

    【讨论】:

      猜你喜欢
      • 2013-03-19
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2015-09-14
      • 2014-03-15
      • 2021-02-22
      相关资源
      最近更新 更多