title: Receive Express session Id from React app
body: <p>I am learning Express.js, trying to create an api and connect it to React frontend. In express, I'm using express-session to create a session. For authentication, I use passport.js.
  Here is the part of my app.js file:</p>
  <pre><code>const session = require('express-session');
  const mongoDbStore = require('connect-mongodb-session')(session);
  const store = new mongoDbStore({
      uri: 'mongodb://localhost:27017/DB_NAME',
      collection: 'UserSessions'
  });
  
  const app = express();
  
  app.use(cors())
  
  app.use(express.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  const sessionConfig = {
      secret: process.env.SESSION_SECRET,
      resave: false,
      saveUninitialized: true,
      store,
      cookie: {
          expires: Date.now() + 1000 * 60 * 60 * 24 * 7,
          maxAge: 1000 * 60 * 60 * 24 * 7,
          httpOnly: true
      }
  }
  
  app.use(session(sessionConfig));
  
  app.use(passport.initialize());
  app.use(passport.session());
  passport.use(new LocalStrategy(User.authenticate()));
  passport.serializeUser(User.serializeUser());
  passport.deserializeUser(User.deserializeUser())
  
  
  app.listen(8080, () =&gt; {
      console.log('listening on port 8080')
  });
  </code></pre>
  <p><strong>My issue is that when I send a request to my backend from my React app, I don't receive session id as a cookie.</strong> On my frontend, I use axios, to send requests:</p>
  <pre><code>import axios from 'axios';
  
  export default axios.create({
      baseURL: &quot;http://localhost:8080/&quot;,
      headers: {
          'Content-Type': 'application/json',
          'Accept': 'application/json'
      }
  });
  </code></pre>
  <p>Why I don't receive a cookie from backend on my frontend and how can I fix this?
  Thank you!</p>