Heroku -dyno停止运行/休眠,在其中添加'var port = process.env.PORT || 3000'

我是Swift开发人员,而不是本地Node.js开发人员,因此我不熟悉此问题。

我注册了Heroku,创建了一个应用,免费运行了dyno,在450小时之后,我收到了一封电子邮件,上面写着Your app(s) have stopped running and will not restart until you receive more free dyno hours next month.

我添加了我的信用卡以进行验证,并得到了additional free 550 hrs。我立即恢复为1000小时的免费小时,但是一旦这样做,dyno就再也无法运行了。

现在(一周后)我跑步

heroku ps -a myAppName

它说我有1000小时。

Free dyno hours quota remaining this month: 1000h 0m (100%)
Free dyno usage for this app: 0h 0m (0%)

我刚刚跑过heroku ps:restart --app myAppName,然后大约15分钟后又回来了,它仍然说我用过0h 0m (0%)

我跑了heroku logs --app myAppName并遇到了以下错误:

  

错误R10(引导超时)-> Web进程无法绑定到$ PORT   启动60秒

     

使用SIGKILL的停止过程已退出,状态为137状态

     

从开始更改为崩溃

Heroku says更改端口并添加:

const PORT = process.env.PORT || 3000;
app.listen(PORT,() => {
    console.log(`Our app is running on port ${ PORT }`);
});

假设这是dynos停止工作/睡眠的原因,似乎(我不熟悉)我需要将端口代码添加到我的app.js文件中吗? 我不知道要添加哪些模块才能使其正常工作。我要添加什么以使上述端口代码正常工作?例如。上面的代码中的app是什么?

我的procfile

worker: node ./app.js

我的app.js文件

const dotenv = require('dotenv');
dotenv.config();

const admin = require("firebase-admin");
admin.initializeApp({
  credential: admin.credential.cert({
    projectId: process.env.FIREBASE_PROJECT_ID,clientEmail: process.env.FIREBASE_CLIENT_EMAIL,privateKey: process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g,'\n'),}),databaseURL: process.env.FIREBASE_DATABASE_URL
});

const firebase = require('firebase');
const config = {
    apiKey: process.env.FIREBASE_API_KEY,databaseURL: process.env.FIREBASE_DATABASE_URL,storageBucket: process.env.FIREBASE_STORAGE_BUCKET,GCM_SENDER_ID
};
firebase.initializeApp(config);

const algoliasearch = require('algoliasearch');
// rest of code ...

我的package.json文件:

{
  "name": "my project","version": "1.0.0","description": "Config Files","main": "app.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "node app.js"
  },"author": "lance Samaria","license": "ISC","engines": {
    "node": "10.16.0"
  },"dependencies": {
    "algoliasearch": "^3.35.1","dotenv": "^8.2.0","firebase": "^7.2.1","firebase-admin": "^8.6.1","nodejs-latest": "^1.1.0"
  }
}
WY190521 回答:Heroku -dyno停止运行/休眠,在其中添加'var port = process.env.PORT || 3000'

我确实在herehere周围进行了搜索,发现必须安装express模块。我使用了this answer

$ npm install --save express

然后在我添加的app.js文件顶部:

var express = require('express');
var app = express();

const PORT = process.env.PORT || 5000;

app.listen(PORT,() => {
  console.log(`Server is listening on port ${PORT}`);
});

一旦我安装了上面的代码,测功机便重新开始工作。我使用5000代替了here中的3000

本文链接:https://www.f2er.com/3144711.html

大家都在问