Node.js v16.20.0 pm2 OR docker based process handling with 4-16 processes
In our use case, we want to establish an API connection from our server app to a Rest/JSON API (e.g. openverse, wikipedia, flickr, pixabay, etc).
For the request using a clientId/clientSecret, we get a token that is valid for about one hour. This token can then be used to make concrete requests such as searches or CRUD operations.
We want the request for a token to be carried out by maximum one Node.js process, as well as the refetch operation if a token has expired. We want this because some APIs don't like it when tokens are requested multiple times in parallel for the same client.
What is your approach to share such a token between multiple Node.js processes? Other processes may have to wait until a token has been fetched.
Thanks and kind regards
We finally decided to use Redis and Node-Redis [¹] as a package. Works great. In the meantime we also use Redis for caching.