title: This is a general expressjs running on node.js inside a docker container and on the cloud question
body: <p>I have built two docker images.  One with nginx that serves my angular web app and another with node.js that serves a basic express app.  I have tried to access the express app from my browser in two different tabs at the same time.</p>
  
  <p>In one tab the angular dev server (ng serve) serves up the web page.  In the other tab the docker nginx container serves up the web page.</p>
  
  <p>While accessing the node.js express app at the same time from both tabs the data starts to mix and mingle and the results returned to both tabs are a mix mash of the two requests (one from each browser tab)...  </p>
  
  <p>I'll try and make this more simple by showing my express app code here...but to answer this question you may not even need to know what the code is at all...so maybe check the question as stated below the code first.</p>
  
  <pre><code>'use strict';
  
  /***********************************
  GOOGLE GMAIL AND OAUTH SETUP
  ***********************************/
  const fs = require('fs');
  const {google} = require('googleapis');
  const gmail = google.gmail('v1');
  
  const clientSecretJson = JSON.parse(fs.readFileSync('./client_secret.json'));
  const oauth2Client = new google.auth.OAuth2(
    clientSecretJson.web.client_id,
    clientSecretJson.web.client_secret,
    'https://us-central1-labelorganizer.cloudfunctions.net/oauth2callback'
  );
  
  
  /***********************************
  EXPRESS WITH CORS SETUP
  ***********************************/
  const PORT = 8000;
  const HOST = '0.0.0.0';
  const express = require('express');
  const cors = require('cors');
  const cookieParser = require('cookie-parser');
  const bodyParser = require('body-parser');
  
  const whiteList = [
    'http://localhost:4200',
    'http://localhost:80',
    'http://localhost',
  ];
  
  const googleApi = express();
  
  googleApi.use(
    cors({
      origin: whiteList
    }),
    cookieParser(),
    bodyParser()
  );
  
  function getPageOfThreads(pageToken, userId, labelIds) {
  
    return new Promise((resolve, reject) =&gt; {
      gmail.users.threads.list(
        {
          'auth': oauth2Client,
          'userId': userId,
          'labelIds': labelIds,
          'pageToken': pageToken
        },
        (error, response) =&gt; {
          if (error) {
            console.error(error);
            reject(error);
          }
          resolve(response.data);
        }
      )
    });
  }
  
  async function getPages(nextPageToken, userId, labelIds, result) {
  
    while (nextPageToken) {
      let pageOfThreads = await getPageOfThreads(nextPageToken, userId, labelIds);
      console.log(pageOfThreads.nextPageToken);
      pageOfThreads.threads.forEach((thread) =&gt; {
        result = result.concat(thread.id);
      })
      nextPageToken = pageOfThreads.nextPageToken;
    }
    return result;
  }
  
  
  googleApi.post('/threads', (req, res) =&gt; {
    console.log(req.body);
    let threadIds = [];
  
    oauth2Client.credentials = req.body.token;
    let getAllThreadIds = new Promise((resolve, reject) =&gt; {
      gmail.users.threads.list(
      { 'auth': oauth2Client, 'userId': 'me', 'maxResults': 500 },
  
        (err, response) =&gt; {
          if (err) {
            console.error(err)
            reject(err);
          }
          if (response.data.threads) {
            response.data.threads.forEach((thread) =&gt; {
              threadIds = threadIds.concat(thread.id);
            });
          }
          if (response.data.nextPageToken) {
              getPages(response.data.nextPageToken, 'me', ['INBOX'], threadIds).then(result =&gt; {
                resolve(result);
              }).catch((err) =&gt; {
                console.error(err);
                reject(err);
              });
          } else {
            resolve(threadIds);
          }
        }
      );
    });
  
    getAllThreadIds
      .then((result) =&gt; {
        res.send({ threadIds: result });
      })
      .catch((error) =&gt; {
        res.status(500).send({ error: 'Request failed with error: ' + error })
      });
  
  });
  
  googleApi.get('/', (req, res) =&gt; res.send('Hello World!'))
  
  googleApi.listen(PORT, HOST);
  console.log(`Running on http://${HOST}:${PORT}`);
  </code></pre>
  
  <p>The angular app makes a simple request to the express app and waits for the reply...which it properly receives...but when I try to make two requests at the exact same time data starts to get mixed together and results are given back to each browser tab from different accounts...</p>
  
  <p><strong>...and the question is...</strong> When running containers in the cloud is this kind of thing an issue? Does one need to spin up a new container for each client that wants to actively connect to the express service so that their data doesn't get mixed? </p>
  
  <p><em>...or is this an issue I am seeing because the express app is being accessed from locally inside my machine?  If two machines with two different ip address tried to access this express server at the same time would this sort of data mixing still be an issue or would each get back it's own set of results?</em></p>
  
  <p>Is this why people use CaaS instead of IaaS solutions?</p>
  
  <p>FYI: this is demo code and the data will not be actually going back to the consumer directly...plans are to have it placed into a database and then re-extracted from the database to download all of the metadata headers for each email.</p>
  
  <p>-Thank you for your time</p>