對于我的應用程式后端,我試圖在 heroku 上托管。在 heroku 上創建一個新應用程式后,我已經按照它向我展示的所有步驟并成功部署了它。但是當我轉到鏈接時,它給了我應用程式錯誤。我試圖讓日志heroku logs --tail過去,它給了我這個
2021-12-29T07:57:12.741895 00:00 app[web.1]: Error: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2021-12-29T07:57:12.751654 00:00 app[web.1]: [nodemon] clean exit - waiting for changes before restart
2021-12-29T07:58:11.201323 00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2021-12-29T07:58:11.236815 00:00 heroku[web.1]: Stopping process with SIGKILL
2021-12-29T07:58:11.259774 00:00 app[web.1]: Error waiting for process to terminate: No child processes
2021-12-29T07:58:11.400798 00:00 heroku[web.1]: Process exited with status 22
2021-12-29T07:58:11.473743 00:00 heroku[web.1]: State changed from starting to crashed
2021-12-29T08:56:18.088383 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=pin-map-app.herokuapp.com request_id=30848095-cca3-4afe-b1ac-705529a0b023 fwd="103.166.88.18" dyno= connect= service= status=503 bytes= protocol=https
2021-12-29T08:56:19.043794 00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=pin-map-app.herokuapp.com request_id=dedb7d05-a475-4e11-972d-e484b397c88e fwd="103.166.88.18" dyno= connect= service= status=503 bytes= protocol=https
正如你所看到的,有一些openUri()問題,為此我已經設定dotenv并添加dotenv.config()到我的index.js. 我heroku restart再次嘗試并推送所有代碼,但問題仍然存在。
索引.js
import express from "express";
import mongoose from "mongoose";
import pinRoutes from "./routes/pins.js";
import userRoutes from "./routes/users.js";
import cors from "cors";
import dotenv from "dotenv";
dotenv.config();
const app = express();
app.use(express.json({ limit: "30mb", extended: true }));
app.use(cors());
app.use("/pins", pinRoutes);
app.use("/user", userRoutes);
const PORT = process.env.PORT || 5000;
app.get("/", (req, res) => {
res.send("welcome to pin it");
});
mongoose
.connect(process.env.CONNECTION_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});
})
.catch((err) => {
console.log("Error: ", err.message);
});
在我的.env檔案中,我只有CONNECTION_URL,沒有別的。我之前部署了一些其他應用程式,但這是我第一次遇到此類錯誤。
uj5u.com熱心網友回復:
- 首先:確保所有的獨立性都安裝在
package.json
其次:
盡管您的設定正確的環境,那說明你的mongoose錯誤告訴大家,什么是錯在你的第一個引數,盡量讓直接鏈接,而不 .env
只要確保它連接的埠是:
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
this just makes the port that connected dynamic
If port 3000 does not work will switch to another one.
并將其聽為:
app.listen(port)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/396845.html
上一篇:在手臂組件中查找陣列中的最小元素
