title: How do I get my server.js to access redux values?
body: <p>I have a checkout page for a store that has some inputs such as address, name, etc. I also want to upload the cart info to the mongodb as well, but it's not working. The cart info comes from redux using the useSelector from redux, but I can't put that function into server.js. Does anyone have any tips? I have provided the schema below as well.</p>
  <p>Server.js</p>
  <pre><code>require('dotenv').config();
  const express = require('express');
  const mongoose = require('mongoose');
  const bodyParser = require('body-parser');
  const connectDB = require('./config/db');
  const productRoutes = require('./routes/productRoutes');
  const CustomerInfo = require(&quot;./models/customerInfo&quot;);
  
  connectDB();
  
  const app = express();
  
  app.use(express.json());
  
  app.use('/api/products', productRoutes);
  
  const PORT = process.env.PORT || 5000;
  
  app.use(bodyParser.urlencoded({extended: true}));
  
  
  //app.post
  
  app.post (&quot;/&quot;, function(req, res) {
      let newCustomerInfo = new CustomerInfo({
          fname: req.body.firstName,
          lname: req.body.lastName,
          email: req.body.email,
          phone: req.body.phoneNumber,
          address: req.body.address,
          city: req.body.city,
          district: req.body.district,
          section: req.body.section,
          confirmCode: req.body.confirmCode,
          comments: req.body.extraInfo,
          cartItems: req.body.cartcount
      });
      newCustomerInfo.save();
      res.redirect(&quot;/&quot;);
  })
  
  app.listen(PORT, () =&gt; console.log(`Server Running on port ${PORT}`))
  </code></pre>
  <p>CheckoutScreen.js</p>
  <pre><code>import './CheckoutScreen.css';
  import { useDispatch, useSelector } from 'react-redux';
  import { Link } from 'react-router-dom';
  
  // Components
  import CartItem from '../components/CartItem';
  
  
  const CheckoutScreen = () =&gt; {
  
      const cart = useSelector(state =&gt; state.cart);
      const { cartItems } = cart;
  
      const getCartCount = () =&gt; {
          return cartItems.reduce((qty, item) =&gt; Number(item.qty) + qty, 0)
      };
  
      const getCartSubTotal = () =&gt; {
          return cartItems.reduce((price, item) =&gt; item.price * item.qty + price, 0)
      };
      return (
          &lt;div className=&quot;checkoutscreen&quot;&gt;
              &lt;div className=&quot;checkout__left&quot;&gt;
                  &lt;body&gt;
                      &lt;form className=&quot;checkout-form&quot; method=&quot;post&quot; action=&quot;/&quot;&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;firstName&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;First Name&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;lastName&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Last Name&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;email&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Email&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;phoneNumber&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Phone Number&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;address&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Address&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;city&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;City&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;district&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;District&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;section&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Section&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;confirmCode&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Confirmation Code&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;label className=&quot;input&quot;&gt;
                              &lt;input type=&quot;text&quot; name=&quot;extraInfo&quot; required/&gt;
                              &lt;span className=&quot;placeholder&quot;&gt;Details/Comments&lt;/span&gt;
                          &lt;/label&gt;
                          &lt;p className=&quot;cartcount&quot;&gt;{getCartCount()}&lt;/p&gt;
                          &lt;button&gt;Submit&lt;/button&gt;
                      &lt;/form&gt;
                  &lt;/body&gt;
              &lt;/div&gt;
              &lt;div className =&quot;checkout__right&quot;&gt;
              &lt;div className=&quot;checkout__info&quot;&gt;
                      &lt;p&gt;Subtotal ({getCartCount()}) items&lt;/p&gt;
                      &lt;p&gt;${getCartSubTotal().toFixed(2)}&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      )
  };
  
  
  
  export default CheckoutScreen;
  </code></pre>
  <p>customerInfo.js</p>
  <pre><code>const mongoose = require(&quot;mongoose&quot;);
  
  const customerInfoSchema = new mongoose.Schema ({
      fname: {
          type: String,
          required: true
      },
      lname: {
          type: String,
          required: true
      },
      email: {
          type: String,
          required: true
      },
      phone: {
          type: String,
          required: true
      },
      address: {
          type: String,
          required: true
      },
      city: {
          type: String,
          required: true
      },
      district: {
          type: String,
          required: true
      },
      section: {
          type: String,
          required: true
      },
      confirmCode: {
          type: String,
          required: true
      },
      comments: {
          type: String,
          required: false
      },
      cartItems: {
          type: Number,
          required: true
      }
  });
  
  const customerInfo = mongoose.model('Customer Info', customerInfoSchema);
  
  module.exports = customerInfo;
  </code></pre>