I'm creating an API using Express, and I want to know if there is a way to create a global variable (something like a global store) that only keeps data for the duration of the request.
I understand that because Node.js handles all requests in the same thread, any global variable I create will persist across requests. So I wonder if there's a clean way to achieve what I want to.
Does Node.js or Express provide a way where I could clean up this global state at the end of each request? Like an event or something similar. Or is there a package that already does this?
Maybe I could get way leveraging closures, but I'm looking for something more flexible.