title: MongoError: failed to connect to server [localhost:27017] on first connect
body: <p>I have paid a membership and downloaded <a href="https://thinkster.io/tutorials/mean-stack" rel="noreferrer">this project</a>. After <code>npm install</code> and <code>node app.js</code>, it returns the following error:</p>
  
  <p>Does anyone know what's wrong?</p>
  
  <pre><code>/Users/Thomas/Desktop/mean-stack-tutorial-01$ node app.js 
  
  /Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb/lib/server.js:265
          process.nextTick(function() { throw err; })
                                        ^
  MongoError: failed to connect to server [localhost:27017] on first connect
      at Pool.&lt;anonymous&gt; (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/topologies/server.js:325:35)
      at emitOne (events.js:96:13)
      at Pool.emit (events.js:188:7)
      at Connection.&lt;anonymous&gt; (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/pool.js:270:12)
      at Connection.g (events.js:292:16)
      at emitTwo (events.js:106:13)
      at Connection.emit (events.js:191:7)
      at Socket.&lt;anonymous&gt; (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/connection.js:173:49)
      at Socket.g (events.js:292:16)
      at emitOne (events.js:96:13)
      at Socket.emit (events.js:188:7)
      at emitErrorNT (net.js:1281:8)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickCallback (internal/process/next_tick.js:98:9)
  </code></pre>
  
  <p><strong>Edit 1:</strong> Following the comments, I just installed mongo via <code>brew</code>, and did <code>brew services start mongodb</code> and then <code>mongo</code>:</p>
  
  <pre><code>/Users/Thomas$ mongo
  MongoDB shell version v3.4.1
  connecting to: mongodb://127.0.0.1:27017
  MongoDB server version: 3.4.1
  Server has startup warnings: 
  2017-01-12T19:53:01.868+0800 I CONTROL  [initandlisten] 
  2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
  2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
  2017-01-12T19:53:01.869+0800 I CONTROL  [initandlisten] 
  </code></pre>
  
  <p>Then I did </p>
  
  <pre><code>/Users/Thomas$ mongod -httpinterface --dbpath /Users/Thomas/Desktop/MongoDB/db
  2017-01-12T20:14:05.620+0800 I CONTROL  [initandlisten] MongoDB starting : pid=47356 port=27017 dbpath=/Users/Thomas/Desktop/MongoDB/db 64-bit host=Pro.local
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] db version v3.4.1
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] allocator: system
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] modules: none
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] build environment:
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten]     distarch: x86_64
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten]     target_arch: x86_64
  2017-01-12T20:14:05.621+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "/Users/Thomas/Desktop/MongoDB/db" } }
  2017-01-12T20:14:05.657+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,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),
  2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
  2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
  2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
  2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
  2017-01-12T20:14:14.108+0800 I CONTROL  [initandlisten] 
  2017-01-12T20:14:14.109+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
  2017-01-12T20:14:15.390+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/Thomas/Desktop/MongoDB/db/diagnostic.data'
  2017-01-12T20:14:16.303+0800 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
  2017-01-12T20:14:16.304+0800 I INDEX    [initandlisten]      building index using bulk method; build may temporarily use up to 500 megabytes of RAM
  2017-01-12T20:14:16.406+0800 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
  2017-01-12T20:14:16.407+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
  2017-01-12T20:14:16.407+0800 I NETWORK  [thread1] waiting for connections on port 27017
  </code></pre>
  
  <p>Then in another terminal, I did <code>node app.js</code>, which hangs (and does not print anything). Then I does <code>http://localhost:28017</code> in a browser, it seems to work:</p>
  
  <p><a href="https://i.stack.imgur.com/zxCxTm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zxCxTm.png" alt="enter image description here"></a></p>
  
  <p>However, how could I see the website?</p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>The normal process is</p>
  
  <ol>
  <li><p>install mongo</p></li>
  <li><p><code>brew services start mongodb</code> in a terminal</p></li>
  <li><p><code>mongo &amp;</code> (assume we use the default folder <code>/data/db/</code>)</p></li>
  <li><p><code>npm start</code></p></li>
  <li><p>see e.g., <code>bin/www</code> for the port number, then use <code>localhost:the_port_number</code> in a browser</p></li>
  </ol>