Map not saving in TypeScript
# workers-help
n
i have a really weird bug when working with cloudflare workers (compiling from typescript) when I set some data to a Map from command.ts, all entries disappear in callback.ts code: https://tsplay.dev/NVRlqN

https://cdn.discordapp.com/attachments/1109392374318243952/1109392374490222612/image.png

https://cdn.discordapp.com/attachments/1109392374318243952/1109392374779609148/image.png

i
Workers are a serverless service. What that means is that you don't hit the same server every time, which helps distribute load. That also means that if Worker 1 sets something in global scope (bad practice anyway since global scope is shared between requests) and then you make a request which hits another server, they won't see each other's changes. Instead, use a service like Cloudflare's KV (https://developers.cloudflare.com/workers/runtime-apis/kv/) to persist data.
n
oh thanks, can I somehow store functions to kv? (that was my original plan but I changed it to a string map for testing)
i
No, you can't. And Functions can't be constructed dynamically from a string at runtime either, for security reasons.
n
thanks for the help, works now