title: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
body: <p>I used mongoose to connect my database to my app.</p>
  <p>I got this unexpected error.</p>
  <p><strong>My app.js look like this</strong></p>
  <pre><code>const express = require('express');
  const mongoose = require('mongoose');
  const authRoutes = require('./routes/authRoutes');
  const cookieParser = require('cookie-parser');
  const { requireAuth, checkUser } = require('./middleware/authMiddleware');
  const run = require('./admin/connection');
  
  const app = express();
  
  // middleware
  app.use(express.static('public'));
  app.use(express.json());
  app.use(cookieParser());
  
  const {default : AdminBro} = require('admin-bro');
  const buildAdminRouter = require('./admin/admin.router');
  const options = require('./admin/admin.options');
  const port = 3000;
  
  
  const url = 'mongodb://localhost:27017/dbName';
  let mongooseDb;
  const databaseConnect = async () =&gt; {
    mongooseDb = await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
    .then((result) =&gt; app.listen(3000))
    .catch((err) =&gt; console.log(err));
  
    const db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function() {
      console.log(&quot;we are connected to database&quot;);
    });
    
      const admin = new AdminBro(options)
      const router = buildAdminRouter(admin);
      app.use(admin.options.rootPath, router);
  
    
  };
  databaseConnect();
  </code></pre>
  <p>I already installed mongodb database.</p>
  <p>I already find similar question in stackoverflow but that answers didn't resolve my issue. Any help will be appreciated. Thanks</p>