Nodejs App crashes when deploying on Heroku. Works locally - node.js

I have now spent a couple of days searching for reasons why this is happening and have tried to make sure all file names are consistent both locally and in the git push since I hear that Heroku can be funny about this.
The app works absolutely fine on my local server I should add.
Here is the heroku logs coming from when I restart the app on heroku:
2019-03-04T21:42:46.527650+00:00 heroku[web.1]: State changed from crashed to starting
2019-03-04T21:42:49.314540+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-04T21:42:50.921757+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-04T21:42:50.921775+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-04T21:42:50.921776+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-04T21:42:50.921777+00:00 app[web.1]: DYNO: 'web.1',
2019-03-04T21:42:50.921779+00:00 app[web.1]: PWD: '/app',
2019-03-04T21:42:50.921780+00:00 app[web.1]: HOME: '/app',
2019-03-04T21:42:50.921781+00:00 app[web.1]: PORT: '51817',
2019-03-04T21:42:50.921782+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-04T21:42:50.921783+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-04T21:42:50.921784+00:00 app[web.1]: SHLVL: '1',
2019-03-04T21:42:50.921785+00:00 app[web.1]: PATH:
2019-03-04T21:42:50.921787+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-04T21:42:50.921788+00:00 app[web.1]: PS1:
2019-03-04T21:42:50.921790+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-04T21:42:50.921791+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-04T21:42:50.921792+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-04T21:42:50.921793+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-04T21:42:50.921794+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-04T21:42:50.921795+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-04T21:42:51.723033+00:00 app[web.1]: internal/modules/cjs/loader.js:582
2019-03-04T21:42:51.723058+00:00 app[web.1]: throw err;
2019-03-04T21:42:51.723060+00:00 app[web.1]: ^
2019-03-04T21:42:51.723061+00:00 app[web.1]:
2019-03-04T21:42:51.723063+00:00 app[web.1]: Error: Cannot find module './controllers/createPost'
2019-03-04T21:42:51.723066+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
2019-03-04T21:42:51.723068+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:506:25)
2019-03-04T21:42:51.723069+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2019-03-04T21:42:51.723071+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2019-03-04T21:42:51.723073+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:14:30)
2019-03-04T21:42:51.723074+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2019-03-04T21:42:51.723076+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2019-03-04T21:42:51.723078+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2019-03-04T21:42:51.723079+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2019-03-04T21:42:51.723081+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:529:3)
2019-03-04T21:42:51.723082+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
2019-03-04T21:42:51.723084+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2019-03-04T21:42:51.723086+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
2019-03-04T21:42:51.789482+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-04T21:42:51.770169+00:00 heroku[web.1]: Process exited with status 1
2019-03-04T21:43:12.736446+00:00 heroku[run.9030]: Client connection closed. Sending SIGHUP to all processes
2019-03-04T21:43:13.319723+00:00 heroku[run.9030]: State changed from up to complete
2019-03-04T21:43:13.297680+00:00 heroku[run.9030]: Process exited with status 129
2019-03-04T21:43:16.063306+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=james-node-blog.herokuapp.com request_id=b16a486a-239e-4bc4-9673-4f24febd9265 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https
2019-03-04T21:43:17.018561+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=63cc1508-3943-4251-b424-674186d84e76 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https
Also, the code can be found on my Github repo here:
https://github.com/jameslevine/Nodejs-Blog
I would greatly appreciate some pointers if anyone has any since I am going round in circles at this point.
Thanks in advance!
Update: Resolved 2 errors. First one was the filename change and the second was the fact that .gitignore didn't include the node_modules file. Now app gives this log, which indicates it is no longer crashing. However, I still can't see the app by clicking on Live App on Heroku. Any help there?
I have included logs below:
2019-03-05T08:59:41.441061+00:00 heroku[web.1]: Restarting
2019-03-05T08:59:41.444978+00:00 heroku[web.1]: State changed from up to starting
2019-03-05T08:59:42.400893+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-05T08:59:42.520869+00:00 heroku[web.1]: Process exited with status 143
2019-03-05T08:59:43.970483+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-05T08:59:45.929838+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-05T08:59:45.929860+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-05T08:59:45.929862+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-05T08:59:45.929863+00:00 app[web.1]: DYNO: 'web.1',
2019-03-05T08:59:45.929865+00:00 app[web.1]: PWD: '/app',
2019-03-05T08:59:45.929867+00:00 app[web.1]: HOME: '/app',
2019-03-05T08:59:45.929868+00:00 app[web.1]: PORT: '54093',
2019-03-05T08:59:45.929869+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-05T08:59:45.929870+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-05T08:59:45.929871+00:00 app[web.1]: SHLVL: '1',
2019-03-05T08:59:45.929873+00:00 app[web.1]: PATH:
2019-03-05T08:59:45.929874+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-05T08:59:45.929875+00:00 app[web.1]: PS1:
2019-03-05T08:59:45.929877+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-05T08:59:45.929878+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-05T08:59:45.929879+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-05T08:59:45.929880+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-05T08:59:45.929881+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-05T08:59:45.929882+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-05T08:59:46.787139+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined resave option; provide resave option at index.js:38:9
2019-03-05T08:59:46.787355+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined saveUninitialized option; provide saveUninitialized option at index.js:38:9
2019-03-05T08:59:46.795789+00:00 app[web.1]: (node:4) 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-03-05T08:59:46.796700+00:00 app[web.1]: App listing on port 54093
2019-03-05T08:59:46.804363+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
2019-03-05T08:59:46.804367+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:564:11)
2019-03-05T08:59:46.804369+00:00 app[web.1]: at Pool.emit (events.js:182:13)
2019-03-05T08:59:46.804370+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:317:12)
2019-03-05T08:59:46.804372+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804373+00:00 app[web.1]: at Connection.emit (events.js:182:13)
2019-03-05T08:59:46.804375+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:246:50)
2019-03-05T08:59:46.804377+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804378+00:00 app[web.1]: at Socket.emit (events.js:182:13)
2019-03-05T08:59:46.804380+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:82:8)
2019-03-05T08:59:46.804382+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
2019-03-05T08:59:46.804384+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-03-05T08:59:46.804474+00:00 app[web.1]: (node:4) 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-03-05T08:59:46.804552+00:00 app[web.1]: (node:4) [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-03-05T08:59:47.581487+00:00 heroku[web.1]: State changed from starting to up
2019-03-05T09:00:21.698023+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=james-node-blog.herokuapp.com request_id=55c8cc21-6544-4e4c-800f-62eac6ed8034 fwd="62.30.226.42" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 protocol=https
2019-03-05T09:01:18.887286+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=ccfeba5b-3105-423c-87f6-edfe9ba86584 fwd="62.30.226.42" dyno=web.1 connect=1ms service=55036ms status=503 bytes= protocol=https
Any ideas why it is now not showing live? I am just beginning to research this and think it is something to do with the server not starting but thought I would update on progress as I go along.

I think it's just a typo, you're trying to require createPost in index.js:14 and the file is actually called createpost.js
Error: Cannot find module './controllers/createPost'
It's weird, though, that it's working locally.

Related

Heroku Node/Postgres Deployment Error - code: h10 desc="App crashed" method=GET path="/" status=503

I'm having trouble deploying my Node/Postgres App to Heroku. When I run my deploy script, the build completes, but after opening the database connection, an error is thrown for a missing module. My Procfile contains web: node main.js and my start script in the package.json states "start": "node main".
Below I am attaching a copy of the heroku logs and the code in main.js which is in the root directory.
Heroku Logs
2021-01-09T23:23:17.000000+00:00 app[api]: Build started by user ********#gmail.com
2021-01-09T23:23:34.407776+00:00 app[api]: Release v17 created by user ********#gmail.com
2021-01-09T23:23:34.407776+00:00 app[api]: Deploy 664cb125 by user ********#gmail.com
2021-01-09T23:23:34.721923+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-09T23:23:35.000000+00:00 app[api]: Build succeeded
2021-01-09T23:23:38.364250+00:00 heroku[web.1]: Starting process with command `node main.js`
2021-01-09T23:23:41.218590+00:00 app[web.1]: Opening database connection to shoppies-nominator
2021-01-09T23:23:41.615336+00:00 app[web.1]: internal/modules/cjs/loader.js:818
2021-01-09T23:23:41.615350+00:00 app[web.1]: throw err;
2021-01-09T23:23:41.615350+00:00 app[web.1]: ^
2021-01-09T23:23:41.615351+00:00 app[web.1]:
2021-01-09T23:23:41.615351+00:00 app[web.1]: Error: Cannot find module 'volleyball'
2021-01-09T23:23:41.615352+00:00 app[web.1]: Require stack:
2021-01-09T23:23:41.615353+00:00 app[web.1]: - /app/server/index.js
2021-01-09T23:23:41.615353+00:00 app[web.1]: - /app/main.js
2021-01-09T23:23:41.615355+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
2021-01-09T23:23:41.615356+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
2021-01-09T23:23:41.615357+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-09T23:23:41.615358+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-09T23:23:41.615358+00:00 app[web.1]: at Object.<anonymous> (/app/server/index.js:3:20)
2021-01-09T23:23:41.615359+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-09T23:23:41.615359+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-09T23:23:41.615360+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-09T23:23:41.615360+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-09T23:23:41.615361+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-09T23:23:41.615362+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-09T23:23:41.615362+00:00 app[web.1]: at Object.<anonymous> (/app/main.js:4:13)
2021-01-09T23:23:41.615362+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-09T23:23:41.615363+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-09T23:23:41.615363+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-09T23:23:41.615364+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-09T23:23:41.615365+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
2021-01-09T23:23:41.615366+00:00 app[web.1]: at internal/main/run_main_module.js:17:47 {
2021-01-09T23:23:41.615366+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-01-09T23:23:41.615367+00:00 app[web.1]: requireStack: [ '/app/server/index.js', '/app/main.js' ]
2021-01-09T23:23:41.615367+00:00 app[web.1]: }
2021-01-09T23:23:41.703611+00:00 heroku[web.1]: Process exited with status 1
2021-01-09T23:23:41.752561+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-09T23:58:53.127855+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shoppies-nominator.herokuapp.com request_id=010f5699-f805-4ce0-92a5-74225a0eb610 fwd="69.141.164.13" dyno= connect= service= status=503 bytes= protocol=https
main.js
const {db} = require('./server/db')
const app = require('./server')
const PORT = process.env.PORT || 5409
db.sync()
.then(() => {
console.log('db synced')
app.listen(PORT, (e) => {
if (e) throw (e)
console.log(`Listening on port ${PORT}`)
})
})
Any ideas?

Unable to host node.js app on heroku.Application error is being displayed

Listen method
let port = process.env.PORT;
if (port == null || port == "")
{port = 3000; }
app.listen(port);
app.listen(port, function() {
console.log("Server has started successfully!");
});
Procfile
web: node app.js
Package.json
{
"name": "todolist-v1",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"engines": {
"node": "12.18.0"
},
"dependencies": {
"body-parser": "^1.18.3",
"ejs": "^2.6.1",
"express": "^4.16.3",
"lodash": "^4.17.19",
"mongoose": "^5.9.26"
}
}
After deploying the app on heroku
This is being displayed when I am visiting the specified address in my terminal
After logging the error in terminal
$ heroku logs --tail
2020-08-06T17:58:14.031722+00:00 app[api]: Initial release by user saadahmad728#gmail.com
2020-08-06T17:58:14.031722+00:00 app[api]: Release v1 created by user saadahmad728#gmail.com
2020-08-06T17:58:14.344269+00:00 app[api]: Enable Logplex by user saadahmad728#gmail.com
2020-08-06T17:58:14.344269+00:00 app[api]: Release v2 created by user saadahmad728#gmail.com
2020-08-06T18:27:53.000000+00:00 app[api]: Build started by user saadahmad728#gmail.com
2020-08-06T18:28:08.541198+00:00 app[api]: Deploy 08926525 by user saadahmad728#gmail.com
2020-08-06T18:28:08.541198+00:00 app[api]: Release v3 created by user saadahmad728#gmail.com
2020-08-06T18:28:08.555631+00:00 app[api]: Scaled to web#1:Free by user saadahmad728#gmail.com
2020-08-06T18:28:09.000000+00:00 app[api]: Build succeeded
2020-08-06T18:28:12.043887+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:28:15.554606+00:00 app[web.1]: events.js:292
2020-08-06T18:28:15.554621+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-08-06T18:28:15.554622+00:00 app[web.1]: ^
2020-08-06T18:28:15.554622+00:00 app[web.1]:
2020-08-06T18:28:15.554622+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::43074
2020-08-06T18:28:15.554623+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-08-06T18:28:15.554623+00:00 app[web.1]: at listenInCluster (net.js:1361:12)
2020-08-06T18:28:15.554624+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-08-06T18:28:15.554624+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:28:15.554625+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)
2020-08-06T18:28:15.554625+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-08-06T18:28:15.554626+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-08-06T18:28:15.554627+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-08-06T18:28:15.554627+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-08-06T18:28:15.554628+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-08-06T18:28:15.554628+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:28:15.554629+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-08-06T18:28:15.554629+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:28:15.554629+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-08-06T18:28:15.554630+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:28:15.554630+00:00 app[web.1]: address: '::',
2020-08-06T18:28:15.554631+00:00 app[web.1]: port: 43074
2020-08-06T18:28:15.554631+00:00 app[web.1]: }
2020-08-06T18:28:15.643665+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:28:15.719470+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-06T18:28:15.721915+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-06T18:28:18.063014+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:28:20.963100+00:00 app[web.1]: events.js:292
2020-08-06T18:28:20.963109+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-08-06T18:28:20.963110+00:00 app[web.1]: ^
2020-08-06T18:28:20.963110+00:00 app[web.1]:
2020-08-06T18:28:20.963110+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::131252020-08-06T18:28:20.963111+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)
2020-08-06T18:28:20.963111+00:00 app[web.1]: at listenInCluster (net.js:1361:12)2020-08-06T18:28:20.963111+00:00 app[web.1]: at Server.listen (net.js:1447:7)
2020-08-06T18:28:20.963111+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:28:20.963112+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)
2020-08-06T18:28:20.963112+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)2020-08-06T18:28:20.963112+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-08-06T18:28:20.963113+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)2020-08-06T18:28:20.963117+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-08-06T18:28:20.963118+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)2020-08-06T18:28:20.963118+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2020-08-06T18:28:20.963118+00:00 app[web.1]: Emitted 'error' event on Server instance at:2020-08-06T18:28:20.963118+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:28:20.963119+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {2020-08-06T18:28:20.963119+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:28:20.963119+00:00 app[web.1]: errno: 'EADDRINUSE',2020-08-06T18:28:20.963119+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:28:20.963119+00:00 app[web.1]: address: '::',2020-08-06T18:28:20.963120+00:00 app[web.1]: port: 13125
2020-08-06T18:28:20.963120+00:00 app[web.1]: }2020-08-06T18:28:21.012655+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:28:21.056282+00:00 heroku[web.1]: State changed from starting to crashed2020-08-06T18:28:29.979419+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=20e2dc90-d336-4df4-bf85-921f061bc1c8 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:28:30.848729+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=f2e74a20-48ae-4dfc-bffb-ef19fd6a3d20 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:41:35.920695+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=f9d2e233-529d-4b69-993c-72d1cb0a07f0 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:41:36.396586+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=2b55782b-9c16-4577-a425-2197e1d089c3 fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T18:49:42.523761+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-06T18:49:45.975358+00:00 heroku[web.1]: Starting process with command `node app.js`
2020-08-06T18:49:49.958428+00:00 heroku[web.1]: Process exited with status 1
2020-08-06T18:49:50.010996+00:00 heroku[web.1]: State changed from starting to crashed2020-08-06T18:49:49.868123+00:00 app[web.1]: events.js:292
2020-08-06T18:49:49.868203+00:00 app[web.1]: throw er; // Unhandled 'error' event2020-08-06T18:49:49.868208+00:00 app[web.1]: ^2020-08-06T18:49:49.868208+00:00 app[web.1]: 2020-08-06T18:49:49.868217+00:00 app[web.1]: Error: listen EADDRINUSE: address already in use :::41212
2020-08-06T18:49:49.868217+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1313:16)2020-08-06T18:49:49.868217+00:00 app[web.1]: at listenInCluster (net.js:1361:12)2020-08-06T18:49:49.868218+00:00 app[web.1]: at Server.listen (net.js:1447:7)2020-08-06T18:49:49.868222+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2020-08-06T18:49:49.868222+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:146:5)2020-08-06T18:49:49.868222+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)2020-08-06T18:49:49.868223+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)2020-08-06T18:49:49.868223+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-08-06T18:49:49.868223+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)2020-08-06T18:49:49.868227+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)2020-08-06T18:49:49.868228+00:00 app[web.1]: at internal/main/run_main_module.js:17:472020-08-06T18:49:49.868228+00:00 app[web.1]: Emitted 'error' event on Server instance at:
2020-08-06T18:49:49.868228+00:00 app[web.1]: at emitErrorNT (net.js:1340:8)
2020-08-06T18:49:49.868228+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-08-06T18:49:49.868232+00:00 app[web.1]: code: 'EADDRINUSE',
2020-08-06T18:49:49.868232+00:00 app[web.1]: errno: 'EADDRINUSE',
2020-08-06T18:49:49.868233+00:00 app[web.1]: syscall: 'listen',
2020-08-06T18:49:49.868233+00:00 app[web.1]: address: '::',
2020-08-06T18:49:49.868233+00:00 app[web.1]: port: 41212
2020-08-06T18:49:49.868233+00:00 app[web.1]: }
2020-08-06T19:17:44.469614+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=glacial-garden-21504.herokuapp.com request_id=84715403-a9ea-414d-ad04-e1b2b712f20b fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
2020-08-06T19:17:45.793877+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=glacial-garden-21504.herokuapp.com request_id=1e9c96ca-dab7-4ea5-b870-62b4be7194fc fwd="112.79.249.195" dyno= connect= service= status=503 bytes= protocol=https
^CTerminate batch job (Y/N)? ^C
The above message is being displayed
I am new to heroku and don't know much about it. It would we greatly appreciated if anyone walks me through the path of successfull app deployment.
You are calling app.listen two times. That isn't necessary. The EADDRINUSE error code tells you that you are trying to listen on an address that is already in use, which is what will happen if you call app.listen two times. Just call it once, like so:
let port = process.env.PORT;
if (port == null || port == "") { port = 3000; }
app.listen(port, function() {
console.log("Server has started successfully!");
});

Error while deploying app on Heroku MongoDB connection

I created the app using express and MongoDB. When I run the app locally it runs perfectly.I created a PostDB database on MongoDB atlas and generated and got connection string.I want to deploy this app using heroku but I don't why it gives this error.Please help me. Thanks in advance.
This is my connection string:
mongoose.connect("\mongodb+srv://Admin:minnu#mongodb01.irdlb.mongodb.net/PostDB",{useNewUrlParser:true,useCreateIndex:true, useUnifiedTopology: true},function(err,db){
if (err) {
console.log('Unable to connect to the server. Please start the server. Error:', err);
} else {
console.log('Connected to Server successfully!');
}});
This is the error I get:
2020-07-22T13:10:59.614060+00:00 app[web.1]: commonWireVersion: null
2020-07-22T13:10:59.614061+00:00 app[web.1]: }
2020-07-22T13:10:59.614061+00:00 app[web.1]: }
2020-07-22T13:10:59.631071+00:00 app[web.1]: Unable to connect to the server. Please start the server. Error: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
2020-07-22T13:10:59.631074+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:828:32)
2020-07-22T13:10:59.631075+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
2020-07-22T13:10:59.631076+00:00 app[web.1]: at Object.<anonymous> (/app/Models/User.js:2:10)
2020-07-22T13:10:59.631076+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-22T13:10:59.631077+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-22T13:10:59.631077+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-22T13:10:59.631078+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-22T13:10:59.631078+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1026:19)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at Object.<anonymous> (/app/Routes/Posts.js:6:12)
2020-07-22T13:10:59.631079+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-22T13:10:59.631080+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-22T13:10:59.631080+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1026:19)
2020-07-22T13:10:59.631081+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:72:18) {
2020-07-22T13:10:59.631082+00:00 app[web.1]: reason: TopologyDescription {
2020-07-22T13:10:59.631082+00:00 app[web.1]: type: 'Single',
2020-07-22T13:10:59.631083+00:00 app[web.1]: setName: null,
2020-07-22T13:10:59.631083+00:00 app[web.1]: maxSetVersion: null,
2020-07-22T13:10:59.631083+00:00 app[web.1]: maxElectionId: null,
2020-07-22T13:10:59.631084+00:00 app[web.1]: servers: Map { 'localhost:27017' => [ServerDescription] },
2020-07-22T13:10:59.631084+00:00 app[web.1]: stale: false,
2020-07-22T13:10:59.631085+00:00 app[web.1]: compatible: true,
2020-07-22T13:10:59.631085+00:00 app[web.1]: compatibilityError: null,
2020-07-22T13:10:59.631086+00:00 app[web.1]: logicalSessionTimeoutMinutes: null,
2020-07-22T13:10:59.631086+00:00 app[web.1]: heartbeatFrequencyMS: 10000,
2020-07-22T13:10:59.631086+00:00 app[web.1]: localThresholdMS: 15,
2020-07-22T13:10:59.631087+00:00 app[web.1]: commonWireVersion: null
2020-07-22T13:10:59.631087+00:00 app[web.1]: }
2020-07-22T13:10:59.631087+00:00 app[web.1]: }
2020-07-22T13:11:29.817201+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T13:43:44.978055+00:00 heroku[web.1]: Idling
2020-07-22T13:43:44.980176+00:00 heroku[web.1]: State changed from up to down
2020-07-22T13:43:46.293776+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T13:43:46.385591+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:23:20.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.274124+00:00 app[api]: Deploy 9e2202b9 by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.274124+00:00 app[api]: Release v9 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:23:41.454375+00:00 heroku[web.1]: State changed from down to starting
2020-07-22T15:23:42.000000+00:00 app[api]: Build succeeded
2020-07-22T15:23:43.755247+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:23:46.020199+00:00 app[web.1]:
2020-07-22T15:23:46.020218+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:23:46.020219+00:00 app[web.1]: > node app.js
2020-07-22T15:23:46.020219+00:00 app[web.1]:
2020-07-22T15:23:46.753513+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:23:46.753525+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:23:46.753554+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:23:46.770376+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:23:47.305407+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T15:23:48.056394+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:23:48.059001+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:24:25.538134+00:00 heroku[router]: at=info method=GET path="/" host=shielded-citadel-75286.herokuapp.com request_id=a2276768-c8b4-4937-a8f9-feb2e1cc9d00 fwd="106.200.146.62" dyno=web.1 connect=0ms service=1360ms status=200 bytes=4199 protocol=https
2020-07-22T15:24:26.201469+00:00 heroku[router]: at=info method=GET path="/css/styles.css" host=shielded-citadel-75286.herokuapp.com request_id=1d330f4c-66fd-407c-a8ed-57ba80507318 fwd="106.200.146.62" dyno=web.1 connect=1ms service=9ms status=200 bytes=2179 protocol=https
2020-07-22T15:24:26.284481+00:00 heroku[router]: at=info method=GET path="/images/logo.jpg" host=shielded-citadel-75286.herokuapp.com request_id=96a94f69-2984-4b7f-8e5e-1ae6f12493e6 fwd="106.200.146.62" dyno=web.1 connect=0ms service=11ms status=200 bytes=8897 protocol=https
2020-07-22T15:24:26.318935+00:00 heroku[router]: at=info method=GET path="/images/butterfly.gif" host=shielded-citadel-75286.herokuapp.com request_id=f54f11ef-31a4-4fdf-ad7f-c5d47c354afb fwd="106.200.146.62" dyno=web.1 connect=0ms service=45ms status=200 bytes=687572 protocol=https
2020-07-22T15:24:51.370552+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=shielded-citadel-75286.herokuapp.com request_id=396f3ab9-b44b-4432-888e-792eb45268e2 fwd="106.200.146.62" dyno=web.1 connect=0ms service=5ms status=404 bytes=394 protocol=https
2020-07-22T15:26:13.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:35.089490+00:00 app[api]: Release v10 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:35.089490+00:00 app[api]: Deploy 7fd231d2 by user mamadgiaishwarya#gmail.com
2020-07-22T15:26:36.000000+00:00 app[api]: Build succeeded
2020-07-22T15:26:36.726907+00:00 heroku[web.1]: Restarting
2020-07-22T15:26:36.741521+00:00 heroku[web.1]: State changed from up to starting
2020-07-22T15:26:37.654962+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T15:26:37.782161+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:26:39.941929+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:26:42.451886+00:00 app[web.1]:
2020-07-22T15:26:42.451908+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:26:42.451908+00:00 app[web.1]: > node app.js
2020-07-22T15:26:42.451909+00:00 app[web.1]:
2020-07-22T15:26:43.528332+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:26:43.528343+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:26:43.528344+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:26:43.537025+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:26:43.977021+00:00 heroku[web.1]: State changed from starting to up
2020-07-22T15:26:44.829130+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:26:44.831445+00:00 app[web.1]: Connected to Server successfully!
2020-07-22T15:28:23.000000+00:00 app[api]: Build started by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.263212+00:00 app[api]: Deploy c7cbd9d0 by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.263212+00:00 app[api]: Release v11 created by user mamadgiaishwarya#gmail.com
2020-07-22T15:28:45.446526+00:00 heroku[web.1]: Restarting
2020-07-22T15:28:45.448387+00:00 heroku[web.1]: State changed from up to starting
2020-07-22T15:28:46.000000+00:00 app[api]: Build succeeded
2020-07-22T15:28:46.651703+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-22T15:28:46.746865+00:00 heroku[web.1]: Process exited with status 143
2020-07-22T15:28:49.098450+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-22T15:28:51.924571+00:00 app[web.1]:
2020-07-22T15:28:51.924589+00:00 app[web.1]: > ejs-challenge#1.0.0 start /app
2020-07-22T15:28:51.924589+00:00 app[web.1]: > node app.js
2020-07-22T15:28:51.924589+00:00 app[web.1]:
2020-07-22T15:28:52.898117+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2020-07-22T15:28:52.898161+00:00 app[web.1]: designed for a production environment, as it will leak
2020-07-22T15:28:52.898162+00:00 app[web.1]: memory, and will not scale past a single process.
2020-07-22T15:28:52.905188+00:00 app[web.1]: Server started on port 3000
2020-07-22T15:28:53.428020+00:00 heroku[web.1]: State changed from starting to up
I think you have a mistake in your connection string.
According to MongoDB docs, connection string should start with mongodb://, not with the leading \ in the front.
I also recommend you to use Promises or Async/Await for your connections, like the following snippet below:
// Start connection via Mongoose.
mongoose
.connect(YOUR_CONNECTION_STRING, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
.then(() => {
console.log('Database connected successfully!');
})
.catch((err) => {
console.log('Error connecting with error code:', err);
});
app.listen(PORT, () => {
console.log('Server starts at port...');
}
It makes code much easier to read.
Alternatively, do you have any exceptions that you do not catch before connecting to the database? It might bubble up and crash your database connection for security reasons.

Heroku Node.js error, code=H10 desc="App crashed"

I have looked through a lot of similar topics and have so far been unable to resolve my problem.
I created a MERN app, used Amazon for my assets and tried to deploy it on Heroku.
My app works locally but when I deployed it on Heroku, I got a 'Application Error'.
When I take a look at the heroku logs --tail, this is the final errors I got :
2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
And this is the complete log :
2019-04-27T12:48:09.000000+00:00 app[api]: Build succeeded
2019-04-27T12:48:24.009559+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:27.790744+00:00 app[web.1]:
2019-04-27T12:48:27.790767+00:00 app[web.1]: > joystock#1.0.0 start /app
2019-04-27T12:48:27.790768+00:00 app[web.1]: > node server.js
2019-04-27T12:48:27.790770+00:00 app[web.1]:
2019-04-27T12:48:29.369354+00:00 app[web.1]:
2019-04-27T12:48:29.369392+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:29.369396+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:29.369397+00:00 app[web.1]: ^
2019-04-27T12:48:29.369917+00:00 app[web.1]: MongooseError: 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.
2019-04-27T12:48:29.369920+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:29.369923+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:29.369925+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:29.369928+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:29.369930+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:29.369932+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:29.369933+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:29.369935+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:29.369936+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:29.369938+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:29.369939+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:29.369942+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:29.430850+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:29.434765+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:29.436805+00:00 app[web.1]: npm ERR! joystock#1.0.0 start: `node server.js`
2019-04-27T12:48:29.437062+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:29.437419+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:29.437721+00:00 app[web.1]: npm ERR! Failed at the joystock#1.0.0 start script.
2019-04-27T12:48:29.438013+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:29.457869+00:00 app[web.1]:
2019-04-27T12:48:29.458356+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:29.458709+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-04-27T12_48_29_440Z-debug.log
2019-04-27T12:48:29.555420+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:29.559599+00:00 heroku[web.1]: State changed from crashed to starting
2019-04-27T12:48:29.536335+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:48:38.161883+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:40.468366+00:00 app[web.1]:
2019-04-27T12:48:40.468385+00:00 app[web.1]: > joystock#1.0.0 start /app
2019-04-27T12:48:40.468387+00:00 app[web.1]: > node server.js
2019-04-27T12:48:40.468388+00:00 app[web.1]:
2019-04-27T12:48:41.210741+00:00 app[web.1]:
2019-04-27T12:48:41.210778+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:41.210781+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:41.210783+00:00 app[web.1]: ^
2019-04-27T12:48:41.211208+00:00 app[web.1]: MongooseError: 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.
2019-04-27T12:48:41.211212+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:41.211214+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:41.211216+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:41.211218+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:41.211219+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:41.211221+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:41.211222+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:41.211224+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:41.211225+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:41.211227+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:41.211228+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:41.211231+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:41.220629+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:41.221020+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:41.222262+00:00 app[web.1]: npm ERR! joystock#1.0.0 start: `node server.js`
2019-04-27T12:48:41.222424+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:41.222687+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:41.222855+00:00 app[web.1]: npm ERR! Failed at the joystock#1.0.0 start script.
2019-04-27T12:48:41.223019+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:41.228089+00:00 app[web.1]:
2019-04-27T12:48:41.228288+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:41.228431+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-04-27T12_48_41_224Z-debug.log
2019-04-27T12:48:41.314693+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:41.291941+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
I've already tried/checked :
The port
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Joystock Server running on port ${port}`));
Tried :
heroku restart
Add the engines version in my package.json file
"engines": {
"node": "8.12.0",
"npm": "6.4.1"
},
My config vars (mongoURI) are correctly defined in my heroku settings for this app.
I also tried to recreate the app completely, from scratch, and everything is up to date.
At first, I add no route defined for '/', so I tried to add one in routes/tracks.js
router.get('/', (req, res) => {
res.redirect('/all/page-1');
});
With or without this route, I got the same result.
...and I always end up with the same errors.
This is my current git repos for this app :
https://github.com/Karaza/joystock
I am out of ideas for what to try to do next for fixing my app.
Thank you in advance for you help (:
in file: joystock/config/keys.js... ensure that NODE_ENV is production? there no keys_dev file.
if (process.env.NODE_ENV === 'production') {
module.exports = require('./keys_prod');
} else {
module.exports = require('./keys_dev');
}
i'm not familiar with heroku, but looks like you disable production mode.
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
So i think need check:
process.env.MONGO_URI
process.env.NODE_ENV
In my config vars, I tried to define mongoURI instead of MONGO_URI
It's working now :)

Cannot push Node app to Heroku because MongoDB Authentication Error

I want to deploy my app to heroku using mlab as a service. When I push to heroku and check my heroku logs, I get the error:
MongoError: Authentication failed.
I did some research and it seems to be because my MongoDB shell and server versions don't match. When I try to connect using the mongo shell by typing:
mongo ds129610.mlab.com:29610/heroku_tnswz69w -u <dbuser> -p <dbpassword>
I get:
MongoDB shell version v3.4.2
connecting to: mongodb://ds129610.mlab.com:29610/heroku_tnswz69w
MongoDB server version: 3.2.12
WARNING: shell and server versions do not match
2017-03-14T16:06:21.842-0700 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1459:20
#(auth):6:1
#(auth):1:2
exception: login failed
I've tried to upgrade my server version, but I have not been successful. How can I resolve this issue? Here are my heroku logs, just in case that this isn't the only issue:
2017-03-14T20:14:44.000000+00:00 app[api]: Build succeeded
2017-03-14T20:14:59.777446+00:00 app[api]: Release v9 created by user corey.archharr#gmail.com
2017-03-14T20:14:59.941332+00:00 heroku[web.1]: State changed from crashed
to starting
2017-03-14T20:15:02.970234+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-14T20:15:05.774946+00:00 app[web.1]:
2017-03-14T20:15:05.774962+00:00 app[web.1]: events.js:160
2017-03-14T20:15:05.774963+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-03-14T20:15:05.774964+00:00 app[web.1]: ^
2017-03-14T20:15:05.776680+00:00 app[web.1]: MongoError: Authentication failed.
2017-03-14T20:15:05.776682+00:00 app[web.1]: at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
2017-03-14T20:15:05.776683+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:483:72
2017-03-14T20:15:05.776684+00:00 app[web.1]: at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:429:16)
2017-03-14T20:15:05.776685+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:319:22)
2017-03-14T20:15:05.776685+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:463:5)
2017-03-14T20:15:05.776686+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-03-14T20:15:05.776687+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-03-14T20:15:05.776688+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-03-14T20:15:05.776689+00:00 app[web.1]: at TCP.onread (net.js:548:20)
2017-03-14T20:15:05.776688+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-03-14T20:15:05.851998+00:00 heroku[web.1]: Process exited with status 1
2017-03-14T20:15:05.849610+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-14T20:15:05.850669+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-14T20:15:09.046484+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-14T20:15:12.712501+00:00 heroku[web.1]: Process exited with status 1
2017-03-14T20:15:12.632012+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:319:22)
2017-03-14T20:15:12.630846+00:00 app[web.1]:
2017-03-14T20:15:12.632015+00:00 app[web.1]: at TCP.onread (net.js:548:20)
2017-03-14T20:15:12.630864+00:00 app[web.1]: events.js:160
2017-03-14T20:15:12.632013+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-03-14T20:15:12.630866+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-03-14T20:15:12.632014+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-03-14T20:15:12.630866+00:00 app[web.1]: ^
2017-03-14T20:15:12.632015+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-03-14T20:15:12.632008+00:00 app[web.1]: MongoError: Authentication failed.
2017-03-14T20:15:12.632013+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-03-14T20:15:12.632010+00:00 app[web.1]: at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
2017-03-14T20:15:12.632011+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:483:72
2017-03-14T20:15:12.632011+00:00 app[web.1]: at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:429:16)
2017-03-14T20:15:12.632012+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:463:5)
2017-03-14T20:15:12.729762+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-14T20:15:54.013766+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-chamber-22079.herokuapp.com request_id=13034e5e-049a-42c6-a0b7-37c3f769d416 fwd="209.49.17.173" dyno= connect= service= status=503 bytes= protocol=https
2017-03-14T20:15:54.509374+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=thawing-chamber-22079.herokuapp.com request_id=f0c7f03e-db03-4efc-ba84-cb21e79d31d8 fwd="209.49.17.173" dyno= connect= service= status=503 bytes= protocol=https
2017-03-14T20:18:26.328705+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=thawing-chamber-22079.herokuapp.com request_id=59a6218c-44ef-4c69-b712-173c6b438782 fwd="209.49.17.173" dyno= connect= service= status=503 bytes= protocol=https
2017-03-14T20:18:26.757058+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=thawing-chamber-22079.herokuapp.com request_id=59c15c21-f2b2-4266-b5c7-2c7367e4c136 fwd="209.49.17.173" dyno= connect= service= status=503 bytes= protocol=https
2017-03-14T20:42:56.872743+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-14T20:43:00.417848+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-14T20:43:03.592709+00:00 app[web.1]:
2017-03-14T20:43:03.592728+00:00 app[web.1]: events.js:160
2017-03-14T20:43:03.592729+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-03-14T20:43:03.592730+00:00 app[web.1]: ^
2017-03-14T20:43:03.593930+00:00 app[web.1]: MongoError: Authentication failed.
2017-03-14T20:43:03.593932+00:00 app[web.1]: at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
2017-03-14T20:43:03.593933+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:483:72
2017-03-14T20:43:03.593933+00:00 app[web.1]: at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:429:16)
2017-03-14T20:43:03.593934+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:463:5)
2017-03-14T20:43:03.593934+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:319:22)
2017-03-14T20:43:03.593935+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-03-14T20:43:03.593935+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-03-14T20:43:03.593936+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-03-14T20:43:03.593936+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-03-14T20:43:03.593937+00:00 app[web.1]: at TCP.onread (net.js:548:20)
2017-03-14T20:43:03.686941+00:00 heroku[web.1]: Process exited with status 1
2017-03-14T20:43:03.707557+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-14T21:40:18.936675+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-14T21:40:21.858760+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-14T21:40:25.337623+00:00 heroku[web.1]: Process exited with status 1
2017-03-14T21:40:25.209569+00:00 app[web.1]:
2017-03-14T21:40:25.209587+00:00 app[web.1]: events.js:160
2017-03-14T21:40:25.209589+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-03-14T21:40:25.209590+00:00 app[web.1]: ^
2017-03-14T21:40:25.211925+00:00 app[web.1]: MongoError: Authentication failed.
2017-03-14T21:40:25.211928+00:00 app[web.1]: at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
2017-03-14T21:40:25.211930+00:00 app[web.1]: at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:429:16)
2017-03-14T21:40:25.211929+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:483:72
2017-03-14T21:40:25.211931+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:463:5)
2017-03-14T21:40:25.211931+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:319:22)
2017-03-14T21:40:25.211932+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-03-14T21:40:25.211932+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-03-14T21:40:25.211933+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-03-14T21:40:25.211934+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-03-14T21:40:25.211934+00:00 app[web.1]: at TCP.onread (net.js:548:20)
2017-03-14T21:40:25.353825+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-14T23:09:56.515355+00:00 heroku[web.1]: State changed from crashed to starting
2017-03-14T23:09:59.150824+00:00 heroku[web.1]: Starting process with command `node server.js`
2017-03-14T23:10:01.803320+00:00 heroku[web.1]: Process exited with status 1
2017-03-14T23:10:01.745328+00:00 app[web.1]:
2017-03-14T23:10:01.745344+00:00 app[web.1]: events.js:160
2017-03-14T23:10:01.745349+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-03-14T23:10:01.745349+00:00 app[web.1]: ^
2017-03-14T23:10:01.746159+00:00 app[web.1]: MongoError: Authentication failed.
2017-03-14T23:10:01.746161+00:00 app[web.1]: at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
2017-03-14T23:10:01.746162+00:00 app[web.1]: at /app/node_modules/mongodb-core/lib/connection/pool.js:483:72
2017-03-14T23:10:01.746163+00:00 app[web.1]: at authenticateStragglers (/app/node_modules/mongodb-core/lib/connection/pool.js:429:16)
2017-03-14T23:10:01.746163+00:00 app[web.1]: at Connection.messageHandler (/app/node_modules/mongodb-core/lib/connection/pool.js:463:5)
2017-03-14T23:10:01.746164+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:319:22)
2017-03-14T23:10:01.746165+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-03-14T23:10:01.746165+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-03-14T23:10:01.746166+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-03-14T23:10:01.746167+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-03-14T23:10:01.746167+00:00 app[web.1]: at TCP.onread (net.js:548:20)
2017-03-14T23:10:01.820453+00:00 heroku[web.1]: State changed from starting to crashed

Resources