【发布时间】:2020-12-09 16:55:11
【问题描述】:
我是 nodeJS 的新手,
我想将 Heroku 上的后端上传到前端,但出现此错误
此代码在本地主机中工作, 我在 Heroku 中添加了 NODE_DATABASE
"Error MongoNetworkError", "Error R10 (Boot timeout) -> Web 进程在启动后 60 秒内未能绑定到 $PORT"
我的 app.js
const dotenv = require("dotenv").load();
const express = require("express");
const session = require("express-session");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const morgan = require("morgan");
const cors = require("cors");
const LocalStrategy = require("passport-local").Strategy;
const routes = require("./routes");
const User = require("./models/User");
const MongoStore = require("connect-mongo")(session);
const PORT = process.env.PORT || 9000;
const app = express();
app.use(bodyParser.json());
app.use(morgan("combined"));
app.use(cors());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use(
session({
secret: "Norbert",
resave: false,
saveUninitialized: true,
cookie: { maxAge: 86400000 },
store: new MongoStore({
mongooseConnection: mongoose.connection,
}),
})
);
app.use(express.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(passport.session());
mongoose.connect(process.env.NODE_DATABASE, { useNewUrlParser: true });
const conn = mongoose.connection;
conn.on("error", console.error.bind(console, "connection error:"));
conn.once("open", () => {
console.log("Connected to mlab database!");
app.listen(PORT, () => console.log(`App is listening on port ${PORT}!`));
app.use("/api", routes);
});
heroku 日志
2020-08-20T10:05:53.139695+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:05:54.067319+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:05:55.810360+00:00 app[web.1]: connection error: MongoNetworkError: connection 5 to cluster0-shard-00-01.ho4na.mongodb.net:27017 closed
2020-08-20T10:05:55.810364+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:05:55.810364+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:05:55.810365+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:05:55.810365+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:05:55.810365+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:05:55.810369+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:05:55.810369+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:05:55.810369+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:05:55.810370+00:00 app[web.1]: }
2020-08-20T10:05:55.828088+00:00 app[web.1]: [nodemon] clean exit - waiting for changes before restart
2020-08-20T10:06:50.472320+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:06:50.496970+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:06:50.575809+00:00 heroku[web.1]: Process exited with status 137
2020-08-20T10:06:50.607171+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:06:50.609395+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:06:55.049996+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:06:57.284172+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:06:57.284202+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:06:57.687757+00:00 app[web.1]:
2020-08-20T10:06:57.687800+00:00 app[web.1]: > notes@1.0.0 start /app
2020-08-20T10:06:57.687801+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:06:57.687802+00:00 app[web.1]:
2020-08-20T10:06:58.012979+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:06:58.014501+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:06:58.015004+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:06:58.015615+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:06:59.007296+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:07:01.309982+00:00 app[web.1]: connection error: MongoNetworkError: connection 5 to cluster0-shard-00-00.ho4na.mongodb.net:27017 closed
2020-08-20T10:07:01.309998+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:07:01.310000+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:07:01.310000+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:07:01.310001+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:07:01.310001+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:07:01.310002+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:07:01.310002+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:07:01.310003+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:07:01.310003+00:00 app[web.1]: }
2020-08-20T10:07:01.340827+00:00 app[web.1]: [nodemon] clean exit - waiting for changes before restart
2020-08-20T10:07:55.450102+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:07:55.473020+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:07:55.500784+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2020-08-20T10:07:55.575750+00:00 heroku[web.1]: Process exited with status 22
2020-08-20T10:07:55.620964+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:10:09.137371+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=111d6959-56ad-4449-9ba6-77fa7a426577 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:10:10.310013+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=dba1ddd0-36d1-44f7-886b-1e22f8ca526d fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:11:20.182121+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=fc425fd1-dcce-49e3-b9af-eae31c9d35f5 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:11:20.884144+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=e81ab2e2-c476-494f-a2f3-2c5a3281fc55 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:19:21.000000+00:00 app[api]: Build started by user myemail@gmail.com
2020-08-20T10:19:47.820767+00:00 app[api]: Deploy f6a0950d by user myemail@gmail.com
2020-08-20T10:19:47.820767+00:00 app[api]: Release v14 created by user myemail@gmail.com
2020-08-20T10:19:48.014495+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:19:49.000000+00:00 app[api]: Build succeeded
2020-08-20T10:19:52.366993+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:19:55.049310+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:19:55.049332+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:19:55.560928+00:00 app[web.1]:
2020-08-20T10:19:55.560950+00:00 app[web.1]: > notes@1.0.0 start /app
2020-08-20T10:19:55.560951+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:19:55.560951+00:00 app[web.1]:
2020-08-20T10:19:55.989648+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:19:55.990902+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:19:55.991361+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:19:55.991938+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:19:57.234412+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:19:58.962557+00:00 app[web.1]: the options [useUnifiedTopology] is not supported
2020-08-20T10:19:59.745897+00:00 app[web.1]: /app/node_modules/mongodb/lib/operations/mongo_client_ops.js:474
2020-08-20T10:19:59.745912+00:00 app[web.1]: throw err;
2020-08-20T10:19:59.745913+00:00 app[web.1]: ^
2020-08-20T10:19:59.745913+00:00 app[web.1]:
2020-08-20T10:19:59.745914+00:00 app[web.1]: MongoNetworkError: connection 9 to cluster0-shard-00-00.ho4na.mongodb.net:27017 closed
2020-08-20T10:19:59.745915+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:19:59.745916+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:19:59.745917+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:19:59.745917+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:19:59.745917+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:19:59.745918+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:19:59.745918+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:19:59.745919+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:19:59.745919+00:00 app[web.1]: }
2020-08-20T10:19:59.763100+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...
2020-08-20T10:20:52.546213+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:20:52.568907+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:20:52.691301+00:00 heroku[web.1]: Process exited with status 137
2020-08-20T10:20:52.742514+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:20:52.744625+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-20T10:20:56.145248+00:00 heroku[web.1]: Starting process with command `npm start`
2020-08-20T10:20:58.152568+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
2020-08-20T10:20:58.152590+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
2020-08-20T10:20:58.572627+00:00 app[web.1]:
2020-08-20T10:20:58.572655+00:00 app[web.1]: > notes@1.0.0 start /app
2020-08-20T10:20:58.572656+00:00 app[web.1]: > nodemon --exec babel-node src/app.js
2020-08-20T10:20:58.572656+00:00 app[web.1]:
2020-08-20T10:20:58.948432+00:00 app[web.1]: [nodemon] 1.18.10
2020-08-20T10:20:58.949669+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2020-08-20T10:20:58.950054+00:00 app[web.1]: [nodemon] watching: *.*
2020-08-20T10:20:58.950608+00:00 app[web.1]: [nodemon] starting `babel-node src/app.js`
2020-08-20T10:20:59.976088+00:00 app[web.1]: Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
2020-08-20T10:21:01.137742+00:00 app[web.1]: the options [useUnifiedTopology] is not supported
2020-08-20T10:21:01.921790+00:00 app[web.1]: connection error: MongoNetworkError: connection 8 to cluster0-shard-00-02.ho4na.mongodb.net:27017 closed
2020-08-20T10:21:01.921802+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:21:01.921803+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:21:01.921804+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:21:01.921804+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:21:01.921805+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:21:01.921805+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:21:01.921806+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:21:01.921806+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:21:01.921807+00:00 app[web.1]: }
2020-08-20T10:21:01.933176+00:00 app[web.1]: /app/node_modules/mongodb/lib/operations/mongo_client_ops.js:474
2020-08-20T10:21:01.933178+00:00 app[web.1]: throw err;
2020-08-20T10:21:01.933178+00:00 app[web.1]: ^
2020-08-20T10:21:01.933179+00:00 app[web.1]:
2020-08-20T10:21:01.933180+00:00 app[web.1]: MongoNetworkError: connection 11 to cluster0-shard-00-02.ho4na.mongodb.net:27017 closed
2020-08-20T10:21:01.933180+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:276:9)
2020-08-20T10:21:01.933181+00:00 app[web.1]: at Object.onceWrapper (events.js:422:26)
2020-08-20T10:21:01.933181+00:00 app[web.1]: at TLSSocket.emit (events.js:327:22)
2020-08-20T10:21:01.933182+00:00 app[web.1]: at net.js:674:12
2020-08-20T10:21:01.933182+00:00 app[web.1]: at TCP.done (_tls_wrap.js:563:7) {
2020-08-20T10:21:01.933182+00:00 app[web.1]: name: 'MongoNetworkError',
2020-08-20T10:21:01.933183+00:00 app[web.1]: errorLabels: [ 'TransientTransactionError' ],
2020-08-20T10:21:01.933183+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2020-08-20T10:21:01.933183+00:00 app[web.1]: }
2020-08-20T10:21:01.960242+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...
2020-08-20T10:21:47.512311+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=favnoteback.herokuapp.com request_id=a0b75780-abfa-4727-99b4-cdf9bc42bb62 fwd="85.221.154.50" dyno= connect= service= status=503 bytes=
protocol=https
2020-08-20T10:21:56.438920+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-20T10:21:56.456159+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-20T10:21:56.480098+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2020-08-20T10:21:56.526046+00:00 heroku[web.1]: Process exited with status 22
2020-08-20T10:21:56.561169+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-20T10:21:57.783155+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=favnoteback.herokuapp.com request_id=aa62afa9-ae33-40b3-9b54-d25bed03c5fa fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
2020-08-20T10:21:58.572293+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=favnoteback.herokuapp.com request_id=afed98ae-b48b-4d0f-944e-551cdc703571 fwd="85.221.154.50" dyno= connect= service= status=503 bytes= protocol=https
如果谁在此错误中帮助我,我将不胜感激
【问题讨论】:
-
您的问题是连接到 mongoDB。失败会导致您的应用程序无法运行
app.listen(PORT),从而导致启动超时错误。你的$NODE_DATABASE是什么样的?如果它只是cluster0-shard-00-00.ho4na.mongodb.net:27017,那么它正在尝试建立连接,但它缺少凭据。 -
我的 $NODE_DATABASE "mongodb+srv://admin:
@cluster0.ho4na.mongodb.net/test"