Application error after heroku deployment

Application error after heroku deployment
0

Hi everyone. I have looked through the posts related to this problem and my app continues to fail after making all the changes.

  1. I created an env file for my variables.
  2. I used mongoose and after verifying that it works locally, i moved to mongolabs
  3. I have deployed to Heroku, and set my config vars as instructed.

I don’t know what to do at this point. Here is my github link

This is the error Heroku logs have recorded:

2019-11-28T15:31:31.302750+00:00 app[web.1]: }]
2019-11-28T15:31:31.302751+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:433:11)
2019-11-28T15:31:31.302753+00:00 app[web.1]: at Pool.emit (events.js:210:5)
2019-11-28T15:31:31.302754+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2019-11-28T15:31:31.302756+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:985:11
2019-11-28T15:31:31.302757+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:40:11
2019-11-28T15:31:31.302759+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:262:5)
2019-11-28T15:31:31.302760+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:287:7)
2019-11-28T15:31:31.302761+00:00 app[web.1]: at Object.onceWrapper (events.js:300:26)
2019-11-28T15:31:31.302762+00:00 app[web.1]: at Socket.emit (events.js:210:5)
2019-11-28T15:31:31.302764+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2019-11-28T15:31:31.302765+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2019-11-28T15:31:31.302767+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:80:21)
2019-11-28T15:31:31.302768+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
2019-11-28T15:32:28.250908+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-28T15:32:28.329034+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-28T15:32:28.135872+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-11-28T15:32:28.135872+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-11-28T15:32:28.238186+00:00 heroku[web.1]: Process exited with status 22
2019-11-28T15:32:28.173834+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2019-11-28T15:32:33.338226+00:00 heroku[web.1]: Starting process with command `npm start`
2019-11-28T15:32:35.247077+00:00 app[web.1]:
2019-11-28T15:32:35.247105+00:00 app[web.1]: > [email protected] start /app
2019-11-28T15:32:35.247107+00:00 app[web.1]: > set DEBUG=app & nodemon app.js
2019-11-28T15:32:35.247109+00:00 app[web.1]:
2019-11-28T15:32:35.490180+00:00 app[web.1]: [nodemon] 1.19.4
2019-11-28T15:32:35.491048+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2019-11-28T15:32:35.491611+00:00 app[web.1]: [nodemon] watching dir(s): *.*
2019-11-28T15:32:35.491674+00:00 app[web.1]: [nodemon] watching extensions: js,mjs,json
2019-11-28T15:32:35.492095+00:00 app[web.1]: [nodemon] starting `node app.js`
2019-11-28T15:32:36.058628+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2019-11-28T15:32:36.058655+00:00 app[web.1]: designed for a production environment, as it will leak
2019-11-28T15:32:36.058657+00:00 app[web.1]: memory, and will not scale past a single process.
2019-11-28T15:32:36.064702+00:00 app[web.1]: (node:37) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2019-11-28T15:32:36.064925+00:00 app[web.1]: (node:37) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
2019-11-28T15:32:36.084430+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
2019-11-28T15:32:36.084434+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
2019-11-28T15:32:36.084436+00:00 app[web.1]: name: 'MongoNetworkError',
2019-11-28T15:32:36.084438+00:00 app[web.1]: errorLabels: [Array],
2019-11-28T15:32:36.084439+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2019-11-28T15:32:36.084446+00:00 app[web.1]: }]
2019-11-28T15:32:36.084447+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:433:11)
2019-11-28T15:32:36.084449+00:00 app[web.1]: at Pool.emit (events.js:210:5)
2019-11-28T15:32:36.084450+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2019-11-28T15:32:36.084451+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:985:11
2019-11-28T15:32:36.084453+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:40:11
2019-11-28T15:32:36.084454+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:262:5)
2019-11-28T15:32:36.084455+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:287:7)
2019-11-28T15:32:36.084457+00:00 app[web.1]: at Object.onceWrapper (events.js:300:26)
2019-11-28T15:32:36.084458+00:00 app[web.1]: at Socket.emit (events.js:210:5)
2019-11-28T15:32:36.084459+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2019-11-28T15:32:36.084460+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2019-11-28T15:32:36.084461+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:80:21)
2019-11-28T15:32:36.084511+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
2019-11-28T15:32:36.084587+00:00 app[web.1]: (node:37) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2019-11-28T15:32:36.085418+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
2019-11-28T15:32:36.085420+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
2019-11-28T15:32:36.085421+00:00 app[web.1]: name: 'MongoNetworkError',
2019-11-28T15:32:36.085422+00:00 app[web.1]: errorLabels: [Array],
2019-11-28T15:32:36.085423+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2019-11-28T15:32:36.085424+00:00 app[web.1]: }]
2019-11-28T15:32:36.085426+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:433:11)
2019-11-28T15:32:36.085427+00:00 app[web.1]: at Pool.emit (events.js:210:5)
2019-11-28T15:32:36.085428+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2019-11-28T15:32:36.085429+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:985:11
2019-11-28T15:32:36.085430+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:40:11
2019-11-28T15:32:36.085431+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:262:5)
2019-11-28T15:32:36.085433+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:287:7)
2019-11-28T15:32:36.085434+00:00 app[web.1]: at Object.onceWrapper (events.js:300:26)
2019-11-28T15:32:36.085434+00:00 app[web.1]: at Socket.emit (events.js:210:5)
2019-11-28T15:32:36.085436+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2019-11-28T15:32:36.085437+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2019-11-28T15:32:36.085438+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:80:21)
2019-11-28T15:32:36.085501+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
2019-11-28T15:32:36.086395+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
2019-11-28T15:32:36.086398+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14) {
2019-11-28T15:32:36.086399+00:00 app[web.1]: name: 'MongoNetworkError',
2019-11-28T15:32:36.086401+00:00 app[web.1]: errorLabels: [Array],
2019-11-28T15:32:36.086402+00:00 app[web.1]: [Symbol(mongoErrorContextSymbol)]: {}
2019-11-28T15:32:36.086403+00:00 app[web.1]: }]
2019-11-28T15:32:36.086405+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb/lib/core/topologies/server.js:433:11)
2019-11-28T15:32:36.086406+00:00 app[web.1]: at Pool.emit (events.js:210:5)
2019-11-28T15:32:36.086408+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:562:14
2019-11-28T15:32:36.086409+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/pool.js:985:11
2019-11-28T15:32:36.086411+00:00 app[web.1]: at /app/node_modules/mongodb/lib/core/connection/connect.js:40:11
2019-11-28T15:32:36.086413+00:00 app[web.1]: at callback (/app/node_modules/mongodb/lib/core/connection/connect.js:262:5)
2019-11-28T15:32:36.086414+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb/lib/core/connection/connect.js:287:7)
2019-11-28T15:32:36.086415+00:00 app[web.1]: at Object.onceWrapper (events.js:300:26)
2019-11-28T15:32:36.086417+00:00 app[web.1]: at Socket.emit (events.js:210:5)
2019-11-28T15:32:36.086418+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2019-11-28T15:32:36.086420+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2019-11-28T15:32:36.086421+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:80:21)
2019-11-28T15:32:36.086509+00:00 app[web.1]: (node:37) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
2019-11-28T15:33:26.021849+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=nouquick.herokuapp.com request_id=b965dc59-0d00-446d-b1f4-544ec345caee fwd="197.211.58.9" dyno= connect= service= status=503 bytes= protocol=https
2019-11-28T15:33:33.982179+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-28T15:33:33.880222+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2019-11-28T15:33:33.880315+00:00 heroku[web.1]: Stopping process with SIGKILL
2019-11-28T15:33:33.956952+00:00 heroku[web.1]: Process exited with status 137
2019-11-28T15:33:57.331172+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nouquick.herokuapp.com request_id=dcbfd78e-2fdf-4001-b584-88ca796fa5c7 fwd="197.211.58.9" dyno= connect= service= status=503 bytes= protocol=https
2019-11-28T15:33:57.958210+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nouquick.herokuapp.com request_id=fc7c4503-2a63-4325-af16-38c533ec7f4c fwd="197.211.58.9" dyno= connect= service= status=503 bytes= protocol=https

Hello!

There is an error indicating that the connection failed, which leads me to think that Your app doesn’t have access to the MongoDB instance:

I haven’t used Mongolabs, but when using Atlas, You have to allow Your application IP to to communicate with it, so it may be the problem :slight_smile: .

Thank you.

I haven’t used Atlas before (only looked at it briefly), but I will try this option.

1 Like

So, I have used Atlas, I can send and retrieve data. However, Heroku gives me the same errors.

I just found a very bad thing in Your code: Your app.js has the mongodb URL on the repository :open_mouth:! That’s a security risk.

You should use something like dotenv for development and build the URL using environment variables. A better way of doing it may be like this:

const uri = `mongodb+srv://${process.env.DB_HOST}`;
const options = {
  user: process.env.DB_USER,
  pass: process.env.DB_PASS,
  dbName: process.env.DB_NAME,
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false,
  useCreateIndex: true
};
mongoose.connect(uri, options).then(
  _ => {
    console.info('Database connection stablished');
    app.listen(port, function() {
      debug(`listening on port ${port}`);
    });
  },
  error => {
    console.error('Database connection failed:', error);
    throw new Error('Could not connect to the database');
  }
);

Here is the full app.js code and here You can see the app deployed to heroku.

You have to setup the following variables under Settings -> Config Vars:

DB_NAME=your_database_name
DB_USER=the_user_with_writeAndRead_permission
DB_PASS=the_user_pass
DB_HOST=the_database_host

Hope this helps :slight_smile:.

Thank you. I changed that this morning (my changes have been going to heroku) and was unaware that the repo had to be updated separately. Let me try this.

Figured it out. Thanks for your timely intervention.

1 Like

Hi! @skaparate

Thanks for your assistance with the heroku problem. The app finally works, but I have encountered a new problem:

After I perform basic operations (add a profile, edit or delete), redirecting works, but the changes are not reflected on the frontend, no matter how many times I refresh.

here’s my github : https://github.com/omeizahanif/quick
and the deployed app: https://nouquick.herokuapp.com

Hello again!

On some places, you’re using mongoose incorrectly.

If you want to use async functions with mongoose, you must surround your calls to it with a try… catch, that’s correct, but you cannot provide a callback parameter, otherwise the callback is executed immediately, which prevents you from getting a promise. The correct way to use async would be:

try {
  const found = await MyModel.find().exec()
  console.log(found)
} catch(e) {
  console.error('Something went wrong:', e)
}

I know this is not a solution, but I hope it helps you understand what you’re doing wrong so you can learn :slight_smile:,

Regards!

One more thing:

You’re repeating a lot of code on your views. It’s more useful to create partials instead of creating a new HTML document for each view.

Thanks for your guidance, @skaparate . I have done some studying and made changes on the async functions. However, my UI is not behaving accordingly I read that async only works with node v7 and above (I updated mine, but npm keeps showing me that it is still the previous version , 6.13.1).

I do not know if it is the node version interfering with my code, but please take another look as your feedback has been extremely valuable. Thanks again.

Are you using Linux? If so, you could use NVM (node version manager). This allows you to install node for the current user, which is useful if, for example, you have to reinstall the O.S.

Anyway, keep in mind that the NPM version is different from node. The following is from my own environment:

$ npm -v
# output:
# 6.13.6

$ node -v
# output:
# v12.13.0

With that out of the way, if there are errors, they should be displayed on the console (or wherever you’re running the commands) and should help you understand what the problem is.

Hi @skaparate I don’t use linux, but I finally understand the difference. I have traced the problem to my service worker (I was building a pwa), but, I can’t seem to figure out why the service worker prevents updating the page as i carry out crud operations.

My observation was, as soon as I deactivated the service worker, the page updated in real-time.

UPDATE: I have decided to disable the dynamic cache. It is responsive for serving files that would normally require the internet to carry out operations and therefore will not be required here (since the user will need the internet to make changes).

Thank you so much for your support, @skaparate

1 Like