title: Can not call API from backend mongodb
body: <p>I'm trying to call my mongoDB API but it's giving me this error:</p>
  <blockquote>
  <p>xhr.js:178 GET http://localhost:3000/api/products 404 (Not Found)</p>
  </blockquote>
  <p>Here is how I call my API:</p>
  <pre><code>  useEffect(() =&gt; {
      const fetchItems = async () =&gt; {
        setLoading(true);
        const res = await axios.get(&quot;/api/products&quot;);
        setProducts(res.data);
        setLoading(false);
        console.log(res.data)
      };
      document.title = `Shop - The Beuter`;
      fetchItems();
    }, [props]);
  </code></pre>
  <p>And here is my server.js:</p>
  <pre><code>const express = require(&quot;express&quot;),
      bodyParser = require('body-parser'),
      app = express(),
      cors = require(&quot;cors&quot;),
      port = process.env.PORT || 8000,
      db = &quot;beuter&quot;,
      path = require(&quot;path&quot;),
      server = app.listen(port, () =&gt; console.log(`Listening to on port ${port}`));
  
  app.use(bodyParser.json());
  app.use(cors());
  app.use(express.json());
  
  if (process.env.NODE_ENV === &quot;production&quot;) {
      app.use(express.static('beuter/build'))
  
      app.get('*', (req, res) =&gt; {
          res.sendFile(path.resolve(__dirname, 'beuter', 'build', 'index.html'));
      })
  }
  require(&quot;./server/config/database.config&quot;)(db);
  require(&quot;./server/routes/product.route&quot;)(app);
  </code></pre>
  <p>this is my database.config.js:</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  module.exports = (name) =&gt; {
      mongoose
          .connect(process.env.MONGODB_URI || `mongodb://localhost/${name}`, {
              useNewUrlParser: true,
              useUnifiedTopology: true,
              useFindAndModify: false
          })
          .then(() =&gt; console.log(`Successfully connected to ${name}`))
          .catch((err) =&gt; console.log(err));
  };
  </code></pre>
  <p>How can I fix this problem?</p>
  <p>Here is my github project if you want to look over my code:
  <a href="https://github.com/nathannewyen/the-beuter" rel="nofollow noreferrer">https://github.com/nathannewyen/the-beuter</a></p>