node.js - 部署 github repo with herouku get error: at=error code=H10 desc="App crashed" method=GET path="/"
问题描述
我发现了这个错误。但我找不到解决我的情况的方法。
我index.js
有process.env.PORT
并且在我package.json
已经有节点和纱线的版本。
但我仍然收到以下错误。
这是我的仓库: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 =
解决方案
您需要检查函数 connectDb(),使用 try/catch 来显示错误。你能告诉我文件 .env 和 connectDb
推荐阅读
- python-2.7 - 来自 Docker Hub 存储库的 Dockerfile
- sql - 有没有一种方法可以在 SQL Teradata 中对排名进行分组,然后按照最近的交易对它们进行排序?
- spring-boot - 我们可以在 Spring Boot 中区分同一用户对同一端点的两次 REST 调用吗
- flutter - 如何在PageView中显示堆叠在当前页面下方的一半近页面?
- discord.js - 在一个频道中反应新的按摩
- java - 对象在没有 save() 方法 JPA 的情况下存储在数据库中
- css - SASS - 根据中学班级更改背景
- .net-core - 我在新应用程序的 Startup.cs 中没有 app.UseMvc
- microsoft-graph-api - MS Graph API 使用“authorization_code”授权访问所有日历
- sql - 谁能解释下面的查询是如何工作的?