I'm reading a lot about google cloud functions and I see that you can run an Express App
on a Cloud Function, but I don't find an article o resource that justifies that over have multiple cloud functions.
One the one hand, Cloud Functions is an environment that works with simple, single-purpose functions that are attached to events. On the other hand, Express is a framework that can be used to create a stateful app (among other things).
Actually, Cloud Functions uses Express under the hood in order to handle a request.
As a best practice, you should try to keep minimal code and functionalities on a single function as that is what they are intended for: single independent stateless executions. Still, as it's proved by this post (that I have reproduced), one could deploy an Express app on a Cloud Function and make it work.
Is better to have an Express App with multiple routes?
I haven't managed to find any other post confirming nor denying this but, in my opinion, if you are intending to use multiple routes, you may be better off with Google App Engine or multiple Cloud Functions.
Google App Engine aims to building highly scalable applications on a serverless platform. I think this option would better suit scenario if you are indeed working towards a full API. Also, CF executes once per request, thus the whole Express framework would be executed on every request, much like PHP.
Take a look on how to deploy an Express app on GAE in this post.
When is better to use an Express App over Google Cloud Functions?
When you are intending to build a whole API, not just minor functions that you need to trigger with an event.
Is there any advantage or disadvantage apart from deploying time?
Their aim is different, it's not like an Express app with multiple routes would be in disadvantage when compared to a regular CF, but their aim is different and you should use them in different scenarios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With