title: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
body: <p>I'm new in nodeJS, started learning by following a trailer on youtube, everything goes well until I added the connect function if mongodb,</p>
  
  <pre><code>mongo.connect("mongodb://localhost:27017/mydb")
  </code></pre>
  
  <p>when I run my code on cmd (node start-app), get the following error, </p>
  
  <pre><code>MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
  </code></pre>
  
  <p>Could someone explain me which step I missed ? 
  my code : </p>
  
  <pre><code>var express = require("express");
  var MongoClient = require('mongodb');
  var url = "mongodb://localhost:27017/mydb";
  var webService = require("./webService");
  var server = express();
  
  MongoClient.connect(url, function (err, db) {
      if (err) throw err;
      console.log("Database created!");
      db.close();
  });
  
  server.use(express.urlencoded({ extended: true }));
  
  server.set('views', __dirname);
  
  server.get('/', function (request, response) {
      response.sendFile(__dirname + '/MainPage.html');
  });
  
  server.get('/Sign', function (request, response) {
      response.render(__dirname + '/Sign.ejs');
  });
  
  server.post("/signUp", webService.signUp);
  
  server.post("/createUser", webService.createUser);
  
  server.listen(5500);
  </code></pre>