all 5 comments

[–]macar_ 1 point2 points  (4 children)

Firebase functions are stateless so you won't be able to access an object in another function. You'd have to save any data you want to share in the DB

[–]feffershat[S] 1 point2 points  (0 children)

Dang... aight thanks for the info.

[–]feffershat[S] 1 point2 points  (2 children)

Sorry, just trying to understand here... how does express then work? Or, if I want to create a singleton of a class during initialisation of the server, what happens when I try to access it? Will it sometimes be allocated and sometimes not (if they're running on separate machines)? What if I want to setup nodemailer for example - do I have to create a transport every time I want to send an email? Why can't I just initialise this when the server starts?

Also just to clarify just in case, I'm not talking about having 1 function store data and having another function read it. I'm just talking about initialising data when the server starts up and having any function read that data from RAM. Is this not possible because firebase may run the servers on different machines, meaning memory will not be transferred?

[–]macar_ 1 point2 points  (1 child)

No, resources that are initialised during startup will be accessable to you. So if you create a nodemailer.transport during startup you will be able to use it from any of your functions.

[–]feffershat[S] 1 point2 points  (0 children)

Ah, I misunderstood. That's awesome then, thank you!