Heroku - Mongoose App一直出现同样的错误:MongoError:第一次连接时无法连接到服务器[process.env.MONGOLAB_URI:*****]

时间:2016-10-04 22:51:07

标签: node.js heroku deployment mongoose mlab

这是heroku日志。我现在连接7次尝试连接错误无法连接,应用程序无法运行。是什么赋予了?我正在尝试将此后端API应用程序部署到heroku。

我还安装了所有软件包,包括mongoose-unique-validator。

to_dict

这是我在节点index.js中的设置:

2016-10-04T22:38:20.978272+00:00 heroku[web.1]: Starting process with 

command `npm start`
2016-10-04T22:38:24.273558+00:00 app[web.1]: 
2016-10-04T22:38:24.273583+00:00 app[web.1]: > roomie_api@1.0.0 start /app
2016-10-04T22:38:24.273584+00:00 app[web.1]: > node index.js
2016-10-04T22:38:24.273585+00:00 app[web.1]: 
2016-10-04T22:38:25.332290+00:00 app[web.1]: 
2016-10-04T22:38:25.332301+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-10-04T22:38:25.332303+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-10-04T22:38:25.332303+00:00 app[web.1]:                                       ^
2016-10-04T22:38:25.334773+00:00 app[web.1]: MongoError: failed to connect to server [process.env.MONGOLAB_URI:*****] on first connect
2016-10-04T22:38:25.334775+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-10-04T22:38:25.334776+00:00 app[web.1]:     at emitOne (events.js:90:13)
2016-10-04T22:38:25.334777+00:00 app[web.1]:     at emit (events.js:182:7)
2016-10-04T22:38:25.334777+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-10-04T22:38:25.334778+00:00 app[web.1]:     at g (events.js:273:16)
2016-10-04T22:38:25.334779+00:00 app[web.1]:     at emitTwo (events.js:100:13)
2016-10-04T22:38:25.334779+00:00 app[web.1]:     at emit (events.js:185:7)
2016-10-04T22:38:25.334780+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-10-04T22:38:25.334780+00:00 app[web.1]:     at Socket.g (events.js:273:16)
2016-10-04T22:38:25.334781+00:00 app[web.1]:     at emitOne (events.js:90:13)
2016-10-04T22:38:25.334781+00:00 app[web.1]:     at Socket.emit (events.js:182:7)
2016-10-04T22:38:25.334782+00:00 app[web.1]:     at connectErrorNT (net.js:1010:8)
2016-10-04T22:38:25.334783+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-10-04T22:38:25.334784+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-04T22:38:25.357010+00:00 app[web.1]: 
2016-10-04T22:38:25.374557+00:00 app[web.1]: npm ERR! Linux 3.13.0-95-generic
2016-10-04T22:38:25.377519+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-10-04T22:38:25.377837+00:00 app[web.1]: npm ERR! node v5.11.1
2016-10-04T22:38:25.378727+00:00 app[web.1]: npm ERR! npm  v3.8.6
2016-10-04T22:38:25.378996+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-10-04T22:38:25.379139+00:00 app[web.1]: npm ERR! roomie_api@1.0.0 start: `node index.js`
2016-10-04T22:38:25.379318+00:00 app[web.1]: npm ERR! Exit status 1
2016-10-04T22:38:25.379514+00:00 app[web.1]: npm ERR! 
2016-10-04T22:38:25.379699+00:00 app[web.1]: npm ERR! Failed at the roomie_api@1.0.0 start script 'node index.js'.
2016-10-04T22:38:25.379885+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-10-04T22:38:25.380406+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-10-04T22:38:25.380060+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the roomie_api package,
2016-10-04T22:38:25.380227+00:00 app[web.1]: npm ERR! not with npm itself.
2016-10-04T22:38:25.380596+00:00 app[web.1]: npm ERR!     node index.js
2016-10-04T22:38:25.380769+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-10-04T22:38:25.380946+00:00 app[web.1]: npm ERR!     npm bugs roomie_api
2016-10-04T22:38:25.381111+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-10-04T22:38:25.381291+00:00 app[web.1]: npm ERR!     npm owner ls roomie_api
2016-10-04T22:38:25.381460+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-10-04T22:38:25.393677+00:00 app[web.1]: 
2016-10-04T22:38:25.393683+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-10-04T22:38:25.393684+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-10-04T22:38:25.528779+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-04T22:38:25.518263+00:00 heroku[web.1]: Process exited with status 1
2016-10-04T22:43:00.087160+00:00 heroku[api]: Deploy 504f79b by ************
2016-10-04T22:43:00.087217+00:00 heroku[api]: Release v9 created by ****************
2016-10-04T22:43:00.262314+00:00 heroku[slug-compiler]: Slug compilation started
2016-10-04T22:43:00.262323+00:00 heroku[slug-compiler]: Slug compilation finished
2016-10-04T22:43:00.509478+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-04T22:43:01.920370+00:00 heroku[web.1]: Starting process with command `npm start`
2016-10-04T22:43:03.921615+00:00 app[web.1]: 
2016-10-04T22:43:03.921629+00:00 app[web.1]: > roomie_api@1.0.0 start /app
2016-10-04T22:43:03.921630+00:00 app[web.1]: > nodemon index.js
2016-10-04T22:43:03.921631+00:00 app[web.1]: 
2016-10-04T22:43:04.226979+00:00 app[web.1]: [nodemon] 1.10.2
2016-10-04T22:43:04.230852+00:00 app[web.1]: [nodemon] to restart at any time, enter `rs`
2016-10-04T22:43:04.230854+00:00 app[web.1]: [nodemon] watching: *.*
2016-10-04T22:43:04.230855+00:00 app[web.1]: [nodemon] starting `node index.js`
2016-10-04T22:43:04.800845+00:00 app[web.1]: 
2016-10-04T22:43:04.800856+00:00 app[web.1]: /app/node_modules/mongodb/lib/server.js:261
2016-10-04T22:43:04.800857+00:00 app[web.1]:         process.nextTick(function() { throw err; })
2016-10-04T22:43:04.800858+00:00 app[web.1]:                                       ^
2016-10-04T22:43:04.801623+00:00 app[web.1]: MongoError: failed to connect to server [localhost:27017] on first connect
2016-10-04T22:43:04.801625+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
2016-10-04T22:43:04.801626+00:00 app[web.1]:     at emitOne (events.js:90:13)
2016-10-04T22:43:04.801627+00:00 app[web.1]:     at emit (events.js:182:7)
2016-10-04T22:43:04.801628+00:00 app[web.1]:     at null.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:260:12)
2016-10-04T22:43:04.801628+00:00 app[web.1]:     at g (events.js:273:16)
2016-10-04T22:43:04.801629+00:00 app[web.1]:     at emitTwo (events.js:100:13)
2016-10-04T22:43:04.801629+00:00 app[web.1]:     at emit (events.js:185:7)
2016-10-04T22:43:04.801644+00:00 app[web.1]:     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:162:49)
2016-10-04T22:43:04.801645+00:00 app[web.1]:     at Socket.g (events.js:273:16)
2016-10-04T22:43:04.801645+00:00 app[web.1]:     at emitOne (events.js:90:13)
2016-10-04T22:43:04.801646+00:00 app[web.1]:     at Socket.emit (events.js:182:7)
2016-10-04T22:43:04.801646+00:00 app[web.1]:     at emitErrorNT (net.js:1265:8)
2016-10-04T22:43:04.801647+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-10-04T22:43:04.801648+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
2016-10-04T22:43:04.806979+00:00 app[web.1]: [nodemon] app crashed - waiting for file changes before starting...

2 个答案:

答案 0 :(得分:0)

您的上一个错误(基于时间戳)是

  

MongoError:无法连接到服务器[localhost:27017]

尝试在最新部署localhost后连接到504f79b,因此我假设process.env.MONGOLAB_URI:*****可能是您修复的代码上的先前错误。

你确定你添加了mongolab插件吗?

此外,您确定正确设置了MONGOLAB_URI环境设置吗?

哟可以在heroku仪表板上查看转到你的应用程序&#34;设置&#34;页面或使用cli

$ heroku config --app your_heroku_app_name_here

答案 1 :(得分:0)

您必须在另一个终端中单独启动服务器。 通过在命令提示符下运行命令“mongod”,您可以执行此操作