title: Mongoose fails to connect to localhost: MongoError: failed to connect to server [127.0.0.1:27017]
body: <p>I am working on a repo I downloaded from Github <a href="https://github.com/MessagingBots/MessengerBot" rel="nofollow noreferrer">https://github.com/MessagingBots/MessengerBot</a>, I know the js code is fine. </p>
  
  <p>I have a config file directing the db URL to "mongodb://127.0.0.1:27017/messenger". (I haven't created the db yet)</p>
  
  <p>I have the node app on Heroku, but <code>Heroku Logs</code> fail every time on mongodb connect. </p>
  
  <pre><code>2016-12-02T06:23:31.636339+00:00 app[web.1]: mongodb://127.0.0.1:27017/messenger
  2016-12-02T06:23:31.672354+00:00 app[web.1]: CALLBACK URL IS
  2016-12-02T06:23:31.672434+00:00 app[web.1]: https://cool-scrubland-89690.herokuapp.com/messages/receive/
  2016-12-02T06:23:31.683394+00:00 app[web.1]: students
  2016-12-02T06:23:31.701863+00:00 app[web.1]: listening on port 3124
  2016-12-02T06:23:31.702052+00:00 app[web.1]: Application running at port 48594
  2016-12-02T06:23:31.717752+00:00 app[web.1]: 
  2016-12-02T06:23:31.717764+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:261
  2016-12-02T06:23:31.717766+00:00 app[web.1]:         process.nextTick(function() { throw err; })
  2016-12-02T06:23:31.717767+00:00 app[web.1]:                                       ^
  2016-12-02T06:23:31.718744+00:00 app[web.1]: MongoError: failed to connect to server [127.0.0.1:27017] on first connect
  2016-12-02T06:23:31.718746+00:00 app[web.1]:     at Pool.&lt;anonymous&gt; (/app/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:313:35)
  2016-12-02T06:23:31.718747+00:00 app[web.1]:     at emitOne (events.js:96:13)
  2016-12-02T06:23:31.718747+00:00 app[web.1]:     at Pool.emit (events.js:188:7)
  2016-12-02T06:23:31.718748+00:00 app[web.1]:     at Connection.&lt;anonymous&gt; (/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:271:12)
  2016-12-02T06:23:31.718749+00:00 app[web.1]:     at Connection.g (events.js:291:16)
  2016-12-02T06:23:31.718750+00:00 app[web.1]:     at emitTwo (events.js:106:13)
  2016-12-02T06:23:31.718750+00:00 app[web.1]:     at Connection.emit (events.js:191:7)
  2016-12-02T06:23:31.718751+00:00 app[web.1]:     at Socket.&lt;anonymous&gt; (/app/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:165:49)
  2016-12-02T06:23:31.718752+00:00 app[web.1]:     at Socket.g (events.js:291:16)
  2016-12-02T06:23:31.718752+00:00 app[web.1]:     at emitOne (events.js:96:13)
  2016-12-02T06:23:31.718753+00:00 app[web.1]:     at Socket.emit (events.js:188:7)
  2016-12-02T06:23:31.718754+00:00 app[web.1]:     at emitErrorNT (net.js:1276:8)
  2016-12-02T06:23:31.718754+00:00 app[web.1]:     at _combinedTickCallback (internal/process/next_tick.js:74:11)
  2016-12-02T06:23:31.718755+00:00 app[web.1]:     at process._tickCallback (internal/process/next_tick.js:98:9)
  2016-12-02T06:24:24.832476+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web process failed to bind to $PORT within 60 seconds of launch
  2016-12-02T06:24:24.832543+00:00 heroku[web.1]: Stopping process with SIGKILL
  2016-12-02T06:24:24.958931+00:00 heroku[web.1]: State changed from starting to crashed
  2016-12-02T06:24:24.949820+00:00 heroku[web.1]: Process exited with status 137
  </code></pre>
  
  <p>I have a <code>mongod</code> instance running. <code>mongod</code> properly connects to localhost and is stable</p>
  
  <pre><code>2016-12-02T14:02:26.733+0700 I CONTROL  [initandlisten] MongoDB starting : pid=2706 port=27017 dbpath=/data/db 64-bit host=ME.local
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] db version v3.2.11
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] git version: 009580ad490190ba33d1c6253ebd8d91808923e4
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] allocator: system
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] modules: none
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] build environment:
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten]     distarch: x86_64
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten]     target_arch: x86_64
  2016-12-02T14:02:26.735+0700 I CONTROL  [initandlisten] options: {}
  2016-12-02T14:02:26.738+0700 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
  2016-12-02T14:02:26.739+0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
  2016-12-02T14:02:27.758+0700 I CONTROL  [initandlisten] 
  2016-12-02T14:02:27.759+0700 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
  2016-12-02T14:02:27.763+0700 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
  2016-12-02T14:02:27.763+0700 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
  2016-12-02T14:02:27.767+0700 I NETWORK  [initandlisten] waiting for connections on port 27017
  </code></pre>
  
  <p>The problem might be related to Mongoose. </p>
  
  <p>Anyone could help me out? </p>