title: I keep getting a POST https://localhost:5000/users/add net::ERR_CONNECTION_REFUSED error. I have tried suggested fixes i found here but nothing works
body: <p>I am working on an exercise tracker app using the MERN stack. I have a react JS component that is meant to allow me to add a new user to a database after I press the submit button. I am using axios to send http requests from my front end to server endpoint on the backend. However I keep getting this error </p>
  
  <blockquote>
    <p>POST <a href="https://localhost:5000/users/add" rel="nofollow noreferrer">https://localhost:5000/users/add</a> net::ERR_CONNECTION_REFUSED
    Uncaught (in promise) Error: Network Error at createError
    (0.chunk.js:971) at XMLHttpRequest.handleError (0.chunk.js:466)</p>
  </blockquote>
  
  <p>This is my server side code</p>
  
  <pre><code>const express = require('express');
  const cors = require('cors');
  const mongoose = require('mongoose');
  //mongoose is whats going to help us connect to our mongoDB database
  
  
  require('dotenv').config();
  //this configures si we can have our environment variables in the dotenv file
  
  const app = express();
  const port = process.env.PORT || 5000;
  //this is how we will create our express server 
  
  app.use(cors());
  app.use(express.json());
  //this is our middle ware this will allopw us to parse json
  // cause the server will be sending s=and receiving json
  
  const uri = process.env.ATLAS_URI;
  mongoose.connect(uri, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology:true});
  //uri is where database is stored
  const connection = mongoose.connection;
  connection.once('open',() =&gt;{
      console.log("MongoDB database connection established successfully");
  });
  //once connection is open its going to log the message
  
  const exercisesRouter = require('./routes/excercises');
  const usersRouter = require('./routes/users');
  //importing 
  
  app.use('/excercises',exercisesRouter);
  app.use('/users',usersRouter);
  //use files
  //whenever somebody goes to route url and put /excersies at the end it will show
  //everything in excercises and the same for users
  
  
  app.listen(port,()=&gt;{
      console.log('Server is running on port: ' + port);
  });
  //this is what starts the server. It start listening to a certain port
  </code></pre>
  
  <p>This is my submit function</p>
  
  <pre><code>onSubmit(e){
          e.preventDefault(); //prevents default html form behaviour taking place
          const user = {
              username: this.state.username,
          };
  
          console.log(user);
  
          //sending user data to the backend with post request
          //check user.js file in routes its sending a post request to the user.add api
          axios.post('https://localhost:5000/users/add',user)
              .then(res =&gt; console.log(res.data));
  
          this.setState({
              username: ''
          });
      }
  </code></pre>
  
  <p>This is my route</p>
  
  <pre><code>router.route('/add').post((req,res) =&gt; {
      const username = req.body.username;
  
      const newUser = new User({username});
      //using unsername to create new user
  
      newUser.save()
          .then(() =&gt; res.json('User added')) //after user saved to DB return user added message
          .catch(err =&gt; res.status(400).json('Error ' + err)); //if there is an error return error
  });
  </code></pre>