简体   繁体   中英

heroku: application not showing when deployed

this is my first time using node JS and I've created an app an deployed it to Heroku successfully but the problem is that I'm getting application error when I open it in Heroku. this is m Heroku logs , can somebody please help me to fix this PS: I implemented this app with help of tutorial so I don't think I've coding problems

thanks in advance

 2021-12-08T22:45:05.920222+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:45:05.920222+00:00 app[web.1]: type: 'Single', 2021-12-08T22:45:05.920223+00:00 app[web.1]: setName: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:45:05.920223+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:45:05.920224+00:00 app[web.1]: stale: false, 2021-12-08T22:45:05.920224+00:00 app[web.1]: compatible: true, 2021-12-08T22:45:05.920224+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:45:05.920224+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:45:05.920225+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:45:05.920225+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:45:05.920225+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:45:05.920226+00:00 app[web.1]: } 2021-12-08T22:45:05.920226+00:00 app[web.1]: } 2021-12-08T22:45:06.067519+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:45:06.124048+00:00 heroku[web.1]: State changed from starting to crashed 2021-12-08T22:45:07.631289+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-waters-05043.herokuapp.com request_id=d072ef8a-e480-463f-a5a4-a8e2dc6726f0 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:45:07.967373+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-waters-05043.herokuapp.com request_id=d68d9288-abf3-4af7-be21-d18d5afe52a1 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:47:56.125042+00:00 heroku[web.1]: State changed from crashed to starting 2021-12-08T22:47:58.760706+00:00 heroku[web.1]: Starting process with command `npm start` 2021-12-08T22:48:00.059713+00:00 app[web.1]: 2021-12-08T22:48:00.059745+00:00 app[web.1]: > api-master-nodejs@1.0.0 start /app 2021-12-08T22:48:00.059746+00:00 app[web.1]: > node app.js 2021-12-08T22:48:00.059746+00:00 app[web.1]: 2021-12-08T22:48:14.000000+00:00 app[api]: Build started by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.216637+00:00 app[api]: Release v20 created by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.216637+00:00 app[api]: Deploy 1883c51b by user sebaalchalabi@gmail.com 2021-12-08T22:48:29.965093+00:00 heroku[web.1]: Restarting 2021-12-08T22:48:30.000000+00:00 app[api]: Build succeeded 2021-12-08T22:48:30.572968+00:00 app[web.1]: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 2021-12-08T22:48:30.572988+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:847:32) 2021-12-08T22:48:30.572989+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10 2021-12-08T22:48:30.572989+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 2021-12-08T22:48:30.572990+00:00 app[web.1]: at new Promise (<anonymous>) 2021-12-08T22:48:30.572990+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20) 2021-12-08T22:48:30.572991+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:26:10) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 2021-12-08T22:48:30.572992+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) 2021-12-08T22:48:30.572993+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 { 2021-12-08T22:48:30.572994+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:48:30.572994+00:00 app[web.1]: type: 'Single', 2021-12-08T22:48:30.572994+00:00 app[web.1]: setName: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:48:30.572995+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:48:30.572996+00:00 app[web.1]: stale: false, 2021-12-08T22:48:30.572996+00:00 app[web.1]: compatible: true, 2021-12-08T22:48:30.572996+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:48:30.572996+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:48:30.572997+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:48:30.572997+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:48:30.572997+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:48:30.572998+00:00 app[web.1]: } 2021-12-08T22:48:30.572998+00:00 app[web.1]: } 2021-12-08T22:48:30.712406+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:48:31.885593+00:00 heroku[web.1]: Starting process with command `npm start` 2021-12-08T22:48:32.779803+00:00 app[web.1]: 2021-12-08T22:48:32.779817+00:00 app[web.1]: > api-master-nodejs@1.0.0 start /app 2021-12-08T22:48:32.779818+00:00 app[web.1]: > node app.js 2021-12-08T22:48:32.779818+00:00 app[web.1]: 2021-12-08T22:49:03.195533+00:00 app[web.1]: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 2021-12-08T22:49:03.195546+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:847:32) 2021-12-08T22:49:03.195548+00:00 app[web.1]: at /app/node_modules/mongoose/lib/index.js:351:10 2021-12-08T22:49:03.195548+00:00 app[web.1]: at /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 2021-12-08T22:49:03.195549+00:00 app[web.1]: at new Promise (<anonymous>) 2021-12-08T22:49:03.195550+00:00 app[web.1]: at promiseOrCallback (/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) 2021-12-08T22:49:03.195550+00:00 app[web.1]: at Mongoose._promiseOrCallback (/app/node_modules/mongoose/lib/index.js:1149:10) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:350:20) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:23:10) 2021-12-08T22:49:03.195551+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14) 2021-12-08T22:49:03.195552+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) 2021-12-08T22:49:03.195552+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) 2021-12-08T22:49:03.195553+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 { 2021-12-08T22:49:03.195554+00:00 app[web.1]: reason: TopologyDescription { 2021-12-08T22:49:03.195555+00:00 app[web.1]: type: 'Single', 2021-12-08T22:49:03.195555+00:00 app[web.1]: setName: null, 2021-12-08T22:49:03.195555+00:00 app[web.1]: maxSetVersion: null, 2021-12-08T22:49:03.195555+00:00 app[web.1]: maxElectionId: null, 2021-12-08T22:49:03.195556+00:00 app[web.1]: servers: Map(1) { 'localhost:27017' => [ServerDescription] }, 2021-12-08T22:49:03.195556+00:00 app[web.1]: stale: false, 2021-12-08T22:49:03.195556+00:00 app[web.1]: compatible: true, 2021-12-08T22:49:03.195557+00:00 app[web.1]: compatibilityError: null, 2021-12-08T22:49:03.195557+00:00 app[web.1]: logicalSessionTimeoutMinutes: null, 2021-12-08T22:49:03.195557+00:00 app[web.1]: heartbeatFrequencyMS: 10000, 2021-12-08T22:49:03.195559+00:00 app[web.1]: localThresholdMS: 15, 2021-12-08T22:49:03.195559+00:00 app[web.1]: commonWireVersion: null 2021-12-08T22:49:03.195560+00:00 app[web.1]: } 2021-12-08T22:49:03.195560+00:00 app[web.1]: } 2021-12-08T22:49:03.330999+00:00 heroku[web.1]: Process exited with status 0 2021-12-08T22:49:03.416601+00:00 heroku[web.1]: State changed from starting to crashed 2021-12-08T22:49:06.220751+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-waters-05043.herokuapp.com request_id=8482d148-2f0c-47c0-ac57-961c9c491948 fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https 2021-12-08T22:49:06.584198+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-waters-05043.herokuapp.com request_id=57fafd37-93e0-4273-a836-bac498cffe7d fwd="85.108.198.36" dyno= connect= service= status=503 bytes= protocol=https

app.js:

 const express = require('express'); const morgan = require('morgan'); const mongoose = require('mongoose'); const dotenv = require('dotenv'); const jwt = require('jsonwebtoken'); const http = require('http'); const multer = require("multer"); const app = express(); const server = http.createServer(app); var cors = require('cors') // corsfffffffff app.use(cors()); /************************************** Socket IO Related Start ************************************************/ // config dotenv dotenv.config(); const dbURI = process.env.MONGO_URL || "mongodb://localhost:27017/YourDB"; mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true }).then(result => server.listen(process.env.PORT || 3000) ).catch(err => console.log(err)); app.set('view engine', 'ejs'); app.use(express.json); // app.use(express.urlencoded({ extended: true })); // app.use(morgan("dev")); app.use((req, res, next) => { res.locals.path = req.path; next(); }); const subscribersRouter = require('./routes/subscribers') app.use('/subscribers', subscribersRouter) app.get("/", function(req,res){ res.send("welcome to app"); })

Your environmental variable MONGO_URL is not defined so its trying to connect to localhost.

  1. Log into Heroku
  2. Go to your app
  3. Choose settings
  4. Reveal config vars
  5. Type in the correct path to your mongo database.

Instead of having fallback value, like you have mongodb://localhost:27017/YourDB - itt's usually better just to fail fast and throw an error by using assert when required variables are not defined.

assert(process.env.MONGO_URL, 'Missing connection string for mongo')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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