title: How to send express-session to client not in same url?
body: <p>Can I please get some help, I have been searching all over the internet for this and I cannot seem to find the answer that I am looking for.</p>
  <p>So I would love to implement expression-session and mongoDB as the store, so session creation I managed to get that done and also saving the session within the store i.e MongoDB managed to get that done.</p>
  <p>The problem now comes to when I have to send the session cookie to the client, so I have my server(NodeJS) running on port 5000 and I have the client(ReactJS) running on port 3000, so now how can I send that cookie to the client and flag it as httpOnly cookie?</p>
  <p><strong>This is how I tried to setup express-session</strong></p>
  <pre><code>mongoose
    .connect(MongoURI, {
      useNewUrlParser: true,
      useCreateIndex: true
    })
    .then(() =&gt; console.log(&quot;MongoDB connected...&quot;))
    .catch((err) =&gt; console.log(err));
  const mongoDBstore = new MongoDBStore({
    uri: MongoURI,
    collection: &quot;mySessions&quot;
  });
  app.use(express.urlencoded({ extended: false }));
  app.use(express.json());
  app.use(
    session({
      name: COOKIE_NAME, 
      secret: 'SESS_SECRET',
      resave: true,
      saveUninitialized: false,
      store: mongoDBstore,
      cookie: {
        maxAge: 1000 * 60 * 60 * 3,
        sameSite: false,
        secure: false
      }
    })
  );
  </code></pre>
  <p><strong>This is where I wanted to send the cookie once user logs in</strong></p>
  <pre><code>router.post(&quot;/login&quot;, (req, res) =&gt; {
    const { email, password } = req.body;
    if (!email || !password) {
      return res.status(400).json({ msg: &quot;Please enter all fields&quot; });
    }
    User.findOne({ email }).then((user) =&gt; {
      if (!user) return res.status(400).json({ msg: &quot;User does not   exist&quot; });
      bcrypt.compare(password, user.password).then((isMatch) =&gt; {
        if (!isMatch) return res.status(400).json({ msg: &quot;Invalid    credentials&quot; });
        const sessUser = { id: user.id, name: user.name, email:   user.email };
        req.session.user = sessUser; 
        res.json({ msg: &quot; Logged In Successfully&quot;, sessUser });
      });
    });
  });
  </code></pre>