title: MongoNetworkError: failed to connect to server [localhost:27017] on first connect
body: <p>I'm running into this issue and I can't find anything on it, I believe it has something to do with my connection string? A few classmates ran into this problem but the connection string their using doesn't work for me. Can't figure this one out. Thoughts?</p>
  
  <p>SERVER.JS:</p>
  
  <pre class="lang-js prettyprint-override"><code>var express = require("express");
  var session = require('express-session');
  var mongoose = require('mongoose');
  var bodyParser = require('body-parser');
  const axios = require('axios');
  var app = express();
  
  mongoose.Promise = global.Promise
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs')
  
  mongoose.connect('mongodb://localhost/fuckface')
  
  
  var QuoteSchema = new mongoose.Schema({
      name:  { type: String, required: true, minlength: 10},
      quote: { type: String, required: true, maxlength: 30 },
  }, {timestamps: true });
  
  mongoose.model('Quote', QuoteSchema);
  var Quote = mongoose.model('Quote');
  
  
  app.use(bodyParser.urlencoded({extended: true}))
  app.use(express.static(__dirname + "/static"))
  app.use(session({
      secret: 'kingmonkey',
      resave: false,
      saveUninitialized: true,
      cookie: { maxAge: 60000 }
  }))
  
  app.get('/showform', function(request, response) {
  
      response.render('showform')
  })
  
  app.get('/showquotes', function(request, response) {
      Quote.find({}, function(err, data) {
          if (err) {
              console.log('You need a different career')
          } else {
          response.render('showquotes', {quotes: data})
          }
      })
  })
  
  app.post('/processquote', function(request, response) {
      var quoteInstance = new Quote()
      console.log(request.body, '&lt;&lt;&lt; QUOTE INSTANCE')
      quoteInstance.name = request.body.name
      quoteInstance.quote = request.body.quote
      console.log(quoteInstance.name, quoteInstance.quote)
      quoteInstance.save(function(err){
          console.log('Oopsie dasies, it didnt save')
      })
      response.redirect('showquotes')
  })
  
  
  app.listen(8000, function() {
      console.log('king me 8000')
  })
  </code></pre>
  
  <p>SHOWFORM.EJS:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en" dir="ltr"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form class="quotes" action="/processquote" method="post"&gt;
              Name: &lt;input type="text" name="name" value=""&gt;
              Quote: &lt;textarea placeholder="Enter your quote" name="quote" rows="8" cols="80"&gt;&lt;/textarea&gt;
              &lt;input type="submit" name="submit" value="submit"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>EXPRESS TRACE:</p>
  
  <pre class="lang-none prettyprint-override"><code>[nodemon] restarting due to changes...
  [nodemon] starting `node server.js`
  (node:30200) 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.
  king me 8000
  (node:30200) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND localhost localhost:27017]
  { name: 'er;ofijer;oigj',
    quote: 'erlkfurnfoerfenrfih3riufhi',
    submit: 'submit' } '&lt;&lt;&lt; QUOTE INSTANCE'
  er;ofijer;oigj erlkfurnfoerfenrfih3riufhi
  </code></pre>
  
  <p>MongoDB TRACE:</p>
  
  <pre class="lang-none prettyprint-override"><code>2018-07-09T16:32:40.473-0700 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
  2018-07-09T16:32:40.546-0700 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
  2018-07-09T16:32:40.552-0700 I NETWORK  [initandlisten] waiting for connections on port 27017
  </code></pre>