Dynamic shared memory in local/Google Cloud-hosted NodeJS project

28 Views Asked by At

I'm looking for a recommendation on how to implement dynamic shared memory. Basically, I need .env variables you can update.

I use a .env to set credentials. These are permanent and don't change, and work well.

However, with some of the services I use, I have to get auth for that session (e.g. Etsy and Peoplevox), and it expires later (e.g. in one hour).

At the moment, I don't store the auth. Whenever I call a function that needs the auth, I have a wrapper that gets it, then uses it. However, this is super annoying, as I have low-level functions - like creating a single object - that are then used in high-level functions - such as creating multiple objects - and they all get their own auth unless I explicitly share it from the top-level function.

Pseudocode example:

const createProduct = async (auth, data) => {
  if (!auth) {
    auth = await getAuth();
  }
  const result = await axios(url, data, { headers: auth });
  return result;
};

const createProducts = async (auth, dataArr) => {
  if (!auth) {
    auth = await getAuth();
  }
  return await Promise.all(dataArr.map(async data => createProduct(auth, data)));
};

Additionally, separate hosted functions can't use that auth, even though it's still valid, because I don't have a way to share the auth.

Is there a good way to share this info globally, where it can also be updated if it goes out of date - without using a database, which I think is overkill?

Cheers.

On another local project, I actually rewrote .env with the results of each auth fetch, but as a result I can't deploy it to Google Cloud as that doesn't work.

0

There are 0 best solutions below