简体   繁体   English

面对 Heroku 上的 NodeJS 部署错误,我该如何解决?

[英]Facing NodeJS deploying error on Heroku, how can I fix it?

I deployed my NodeJS app on Heroku, But I'm getting this error: Image of error我在 Heroku 上部署了我的 NodeJS 应用程序,但出现此错误:错误图像

I've tried to deploy my NodeJs app on Heroku, follows all steps on Heroku guide but I can't make it running.我尝试在 Heroku 上部署我的 NodeJs 应用程序,遵循 Heroku 指南上的所有步骤,但我无法使其运行。

How can I fix it?我该如何解决?

This is my app.js :这是我的app.js

const express = require('express');
const app = express();
const path = require('path');

app.get('/', async (req, res) => {

  res.sendFile(path.join(__dirname + '/index.html'));
});

app.post('/hello', async (req, res) => {
   // My code ....
});

app.listen(3000, () => console.log('listening on port 3000'));

This is my Package.json :这是我的Package.json

{
  "name": "amer-api",
  "version": "1.0.0",
  "description": "Amer's personal website api.",
  "author": "Amer Ansari",
  "license": "ISC",
  "homepage": "https://github.com/AmerAnsari/amer-api",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/AmerAnsari/amer-api.git"
  },
  "bugs": {
    "url": "https://github.com/AmerAnsari/amer-api/issues"
  },
  "scripts": {
    "start": "node app.js"
  },
  "main": "app.js",
  "dependencies": {
    "express": "^4.17.1",
    "geoip-lite": "^1.4.2",
    "nodemailer": "^6.4.6"
  }
}

THere is the log ( heroku logs --tail ):这是日志( heroku 日志 --tail ):

amer@pire:~/Documents/GitHub/amer-api$ heroku logs --tail
2020-05-18T00:31:45.124394+00:00 app[api]: Initial release by user am3ransari@gmail.com
2020-05-18T00:31:45.124394+00:00 app[api]: Release v1 created by user am3ransari@gmail.com
2020-05-18T00:31:45.576958+00:00 app[api]: Enable Logplex by user am3ransari@gmail.com
2020-05-18T00:31:45.576958+00:00 app[api]: Release v2 created by user am3ransari@gmail.com
2020-05-18T00:32:22.000000+00:00 app[api]: Build started by user am3ransari@gmail.com
2020-05-18T00:32:49.104161+00:00 app[api]: Deploy 1d131d7d by user am3ransari@gmail.com
2020-05-18T00:32:49.104161+00:00 app[api]: Release v3 created by user am3ransari@gmail.com
2020-05-18T00:32:49.128088+00:00 app[api]: Scaled to web@1:Free by user am3ransari@gmail.com
2020-05-18T00:32:55.009626+00:00 app[web.1]: 
2020-05-18T00:32:55.009659+00:00 app[web.1]: > amer-api@1.0.0 start /app
2020-05-18T00:32:55.009660+00:00 app[web.1]: > node app.js
2020-05-18T00:32:55.009660+00:00 app[web.1]: 
2020-05-18T00:32:55.349511+00:00 app[web.1]: listening on port 3000
2020-05-18T00:32:58.000000+00:00 app[api]: Build succeeded
2020-05-18T00:33:53.578640+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-18T00:33:53.583026+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-18T00:34:01.570180+00:00 app[web.1]: 
2020-05-18T00:34:01.570202+00:00 app[web.1]: > amer-api@1.0.0 start /app
2020-05-18T00:34:01.570202+00:00 app[web.1]: > node app.js
2020-05-18T00:34:01.570203+00:00 app[web.1]: 
2020-05-18T00:34:02.125267+00:00 app[web.1]: listening on port 3000
2020-05-18T00:34:48.531089+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=serene-shelf-12092.herokuapp.com request_id=82d5065f-fcd6-4e9c-8836-7ebb3a075658 fwd="92.99.250.143" dyno= connect= service= status=503 bytes= protocol=https
2020-05-18T00:34:59.080489+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-18T00:35:00.097273+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=serene-shelf-12092.herokuapp.com request_id=aa2cac26-b857-48aa-a2eb-72f9c9abea04 fwd="92.99.250.143" dyno= connect= service= status=503 bytes= protocol=https

Anyone can help me?任何人都可以帮助我吗?

please add path into your dependencies:请将路径添加到您的依赖项中:

npm install path --save

secondly change your app.js last line to this其次将您的 app.js 最后一行更改为此

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`listening on:`, port));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM