首页 > 解决方案 > 部署 github repo with herouku get error: at=error code=H10 desc="App crashed" method=GET path="/"

问题描述

我发现了这个错误。但我找不到解决我的情况的方法。

index.jsprocess.env.PORT并且在我package.json已经有节点和纱线的版本。

但我仍然收到以下错误。

at=错误代码=H10 desc=

这是我的仓库:https ://github.com/Hubert-EC/HubertBE

这是我的package.json

{
  "name": "UTE1.21-EC18A009-BE",
  "version": "1.0.0",
  "main": "index.js",
  "repository": "https://github.com/lvminh/UTE1.21-EC18A009-BE",
  "author": "theleehari <nhai30928@gmail.com>",
  "license": "MIT",
  "engines": {
    "node": "14.15.5",
    "yarn": "1.22.10"
  },
  "scripts": {
    "start": "nodemon app/index.js"
  },
  "dependencies": {
    "@hapi/joi": "^17.1.1",
    "bcrypt": "^5.0.1",
    "body-parser": "^1.19.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.12.2",
    "morgan": "^1.10.0",
    "nodemailer": "^6.5.0",
    "passport": "^0.4.1",
    "passport-facebook-token": "^4.0.0",
    "passport-google-plus-token": "^2.1.0",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "paypal-rest-sdk": "^1.8.1",
    "query-string": "^7.0.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  }
}

这是我的index.js

const express = require("express");
const connectDb = require("./common/connectDb");
const app = express();
//const { PORT} = require("./common/config");
const router = require("./router/index.router");
const bodyParser = require("body-parser");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use("/api", router);

connectDb();

app.use("/", (req, res) => res.send("Hubert"));
app.get('/', (req, res) => {
  res.send("Hubert");
});
app.get("/test-paypal", (req, res) => {
  res.sendFile(__dirname + "/services/Paypal.Services.html");
});
const port = process.env.PORT || 8080
app.listen(port, () => console.log(`Listen on port ${port}`));

这是我的功能connectDb()

const mongoose = require("mongoose");
const { MONGODB_URI } = require("./config");

const connectDb = async () => {

  await mongoose
    .connect(MONGODB_URI, {
      useCreateIndex: true,
      useNewUrlParser: true,
      useUnifiedTopology: true,
    })
    .then(() => console.log("Success!!!!"))
    .catch((error) => console.error("Failed: ", error));
};

module.exports = connectDb;

这是我的.env

#Connect MongoDB
MONGODB_URI = 

#PORT LISTEN
PORT = 8080

#nodemailer config
ADMIN_EMAIL = 
ADMIN_EMAIL_PASSWORD = 
PORT_SEND_MAIL = 

#Json web token value
JWT_SECRET= 

#Google OAuth token
GOOGLE_CLIENT_ID = 
GOOGLE_CLIENT_SECRET = 

#Facebook OAuth token
FACEBOOK_CLIENT_ID = 
FACEBOOK_CLIENT_SECRET = 

#URL
CLIENT_URL = 


#PAYPAL SANDBOX
PAYPAL_CLIENT_ID = 
PAYPAL_CLIENT_SECRET = 

标签: node.jsexpressheroku

解决方案


您需要检查函数 connectDb(),使用 try/catch 来显示错误。你能告诉我文件 .env 和 connectDb


推荐阅读