简体   繁体   中英

Heroku, mLab and Node.js: Application Error - Mongoose

I am new to Node.js and Heroku and am trying to host my first application on Heroku but am having issues with the deployment. I have been following this tutorial to deploy the app: https://scotch.io/tutorials/use-mongodb-with-a-node-application-on-heroku

In cmd prompt I have done the following:
1. heroku
2. heroku login
3. heroku create app 4. git push heroku master
5. heroku ps:scale web=1 6. heroku open
7. heroku logs --tail (below is a list of the log messages I see after heroku open)

On my mLab console I have created a database, collection and user and defined my mongo URI as the following:

'mongodb://admin:********@asdf1234.mlab.com:13122/app'

If I start my Node app locally, I can successfully create data into this database, but when I try to access my app from Heroku, I get the application error webpage. I know I must be missing a steps somewhere? I believe this is related to Mongoose?

2016-05-03T02:27:29.458496+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-03T02:27:33.077531+00:00 heroku[web.1]: Starting process with command `npm start`
2016-05-03T02:27:35.383818+00:00 app[web.1]:
2016-05-03T02:27:35.383872+00:00 app[web.1]: > app@0.0.0 start /app
2016-05-03T02:27:35.383878+00:00 app[web.1]: > node ./bin/www
2016-05-03T02:27:35.383887+00:00 app[web.1]:
2016-05-03T02:27:35.587955+00:00 app[web.1]: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
2016-05-03T02:27:35.589136+00:00 app[web.1]: js-bson: Failed to load c++ bson extension, using pure JS version
2016-05-03T02:27:35.947930+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2016-05-03T02:27:35.947945+00:00 app[web.1]: designed for a production environment, as it will leak
2016-05-03T02:27:35.947946+00:00 app[web.1]: memory, and will not scale past a single process.
2016-05-03T02:27:35.986323+00:00 app[web.1]:
2016-05-03T02:27:35.986338+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
2016-05-03T02:27:35.986339+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-05-03T02:27:35.986341+00:00 app[web.1]:                                       ^
2016-05-03T02:27:35.986344+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:27017
2016-05-03T02:27:35.986345+00:00 app[web.1]:     at Object.exports._errnoException (util.js:893:11)
2016-05-03T02:27:35.986346+00:00 app[web.1]:     at exports._exceptionWithHostPort (util.js:916:20)
2016-05-03T02:27:35.986347+00:00 app[web.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1075:14)
2016-05-03T02:27:35.997520+00:00 app[web.1]:
2016-05-03T02:27:36.009323+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-05-03T02:27:36.009834+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-05-03T02:27:36.010139+00:00 app[web.1]: npm ERR! node v5.11.0
2016-05-03T02:27:36.010913+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-05-03T02:27:36.011252+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-05-03T02:27:36.011483+00:00 app[web.1]: npm ERR! app@0.0.0 start: `node ./bin/www`
2016-05-03T02:27:36.011697+00:00 app[web.1]: npm ERR! Exit status 1
2016-05-03T02:27:36.011937+00:00 app[web.1]: npm ERR!
2016-05-03T02:27:36.012344+00:00 app[web.1]: npm ERR! Failed at the app@0.0.0 start script 'node ./bin/www'.
2016-05-03T02:27:36.012587+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-05-03T02:27:36.012830+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the app package,
2016-05-03T02:27:36.013080+00:00 app[web.1]: npm ERR! not with npm itself.
2016-05-03T02:27:36.013296+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-05-03T02:27:36.013522+00:00 app[web.1]: npm ERR!     node ./bin/www
2016-05-03T02:27:36.013730+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-05-03T02:27:36.013943+00:00 app[web.1]: npm ERR!     npm bugs app
2016-05-03T02:27:36.014152+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-05-03T02:27:36.014360+00:00 app[web.1]: npm ERR!     npm owner ls app
2016-05-03T02:27:36.014579+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-05-03T02:27:36.021124+00:00 app[web.1]:
2016-05-03T02:27:36.021429+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-05-03T02:27:36.021644+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-05-03T02:27:36.772785+00:00 heroku[web.1]: Process exited with status 1
2016-05-03T02:27:36.779023+00:00 heroku[web.1]: State changed from starting to crashed

My package.json file looks like this if that helps:

{
  "name": "app",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "~1.13.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "~1.3.5",
    "debug": "~2.2.0",
    "express": "~4.13.1",
    "express-session": "^1.13.0",
    "jade": "~1.11.0",
    "mongodb": "~1.4.4",
    "mongoose": "^4.4.6",
    "monk": "~1.0.1",
    "morgan": "~1.6.1",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "serve-favicon": "~2.3.0"
  }
}

Thanks for the help!

EDIT:

All I was missing was the node version in my package.json, the following fixed it for me:

"engines": {
    "node": "4.3.2"
  },

The following error:

Error: connect ECONNREFUSED 127.0.0.1:27017

Basically says it's trying to connect to MongoDB on 127.0.0.1 which would be the Heroku container not mLab, are you sure you are reading the MongoDB url from Process.env and trying to connect to that url?

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