title: Trying to get older program to work but get Error [MongoError]: failed to connect to server
body: <p>This is the code for the mongodb server login</p>
  <pre class="lang-js prettyprint-override"><code>/* Moduless */
  const mongoose = require('mongoose');
  const express = require('express');
  const nunjucks = require('nunjucks');
  const bodyParser = require('body-parser');
  const http = require('http');
  const moment = require('moment');
  
  /* Classes and Models */
  const Task = require('./src/classes/Task.js');
  const AppRouter = require('./src/classes/AppRouter.js');
  const Seller = require('./src/models/Seller');
  const Product = require('./src/models/Product');
  
  /* Express Server Setup */
  const app = express();
  app.server = http.createServer(app);
  
  global.status = 'Stopped';
  global.tasks = [];
  global.logs = '';
  global.config = require('./config')
  
  const PORT = global.config.port;
  
  /* MongoDB Connection */
  mongoose.set('debug', false);
  mongoose.Promise = Promise;
  mongoose.connect(global.config.mongodb_uri, (err) =&gt; {
      if (!err) {
  
          Product.remove({}, function(err) {
              if (!err) {
                  console.log('All items in the Product collection have been removed.')
              }
          });
  
          nunjucks.configure('views', {
              autoescape: true,
              watch: true,
              express: app
          });
  
          app.use('/resources', express.static(__dirname + '/resources'));
  
          app.use(bodyParser.json({
              limit: '50mb'
          }));
          app.use(bodyParser.urlencoded({
              extended: true,
              limit: '50mb'
          }));
  
          app.set('view engine', 'html');
  
          new AppRouter(app);
  
          app.server.listen(process.env.PORT || PORT, () =&gt; {
              console.log(`App is running on at http://127.0.0.1:${app.server.address().port}`);
          });
          return;
      }
      console.error('MongoDB connection error. Please make sure MongoDB is running.\n', err);
      process.exit();
  });
  </code></pre>
  
  <p>which seems like it should work but i cant for the life of me get it to connect to my mongodb server. i have mongod running and even mongo just in case but all i ever get is</p>
  <pre class="lang-js prettyprint-override"><code>[Sun Jul 25 2021 11:48:39] [ERROR]  MongoDB connection error. Please make sure MongoDB is running.
   Error [MongoError]: failed to connect to server [cluster0.spjqj.mongodb.net:27017] on first connect [Error: getaddrinfo ENOTFOUND cluster0.spjqj.mongodb.net at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:69:26)
  </code></pre>
  
  <p>i have url encoded my mongodb connection string and tried the mongo compass version of the string and the 3rd party program version of the string and both come back with that message.</p>
  <p>is it just something silly like i need to update some repositories for this program? i.e if mongodb updated alot in the past year or two.</p>