title: MongoDB net::ERR_CONNECTION_REFUSED on server
body: <p>I am trying to make calls to my database from my react/node app hosted on a server. When run locally (using nodemon) the application is running at localhost:3000 and the server is hosted on port 4000, so I make api calls to localhost:4000. For example, <code>localhost:4000/students</code> displays the list of students stored in the MongoDB. </p>
  
  <p>My server.js is as follows:</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const bodyParser = require('body-parser');
  const PORT = 4000;
  const cors = require('cors');
  const mongoose = require('mongoose');
  const studentRoute = require('./student.route');
  const config = require('./secrets');
  
  mongoose.Promise = global.Promise;
  mongoose.connect(config.dbUri, { useNewUrlParser: true }).then(
    () =&gt; {console.log('Database is connected') },
    err =&gt; { console.log('Can not connect to the database'+ err)}
  );
  </code></pre>
  
  <p>I am deploying my application to my site by uploading the build folder that results from <code>npm run build</code> to a folder called 'the-wall' (the name of the project). So to access the application I go to example.com/the-wall.</p>
  
  <p>My mongoDB is hosted using MongoDB atlas, and have whitelisted my IP address and what I believe to be the IP address of the server. I am making calls using axios, with the following config:</p>
  
  <pre><code>
  const env = process.env.NODE_ENV; 
  
  export const app = axios.create({
    baseURL:
      env === 'production'
        ? 'https://example.com:4000/'
        : 'http://localhost:4000/',
  });
  </code></pre>
  
  <p>However, when I try to access example.com:4000/student I receive a <code>net::ERR_CONNECTION_REFUSED</code> error. As far as I can tell, mongoDB is not installed on the server. Is the URL I am using incorrect, or is there additional set up I need to do?</p>
  
  <p>Note: I have also tried example.com/the-wall:4000/student, but I get a 404 error with this one. </p>
  
  <p>Does the way I am trying to make a call to the database look correct? (i.e. is the URL correct with the port, etc) </p>