Running Express app in Firebase Cloud Functions

16 December 2022
Works out of the box
serverless

A couple of years after my first serverless hands-on with Firebase Cloud Functions, I've revisited it I am amazed by the fact that Express app will work out of the box in Cloud Functions.

This will be the perfect for my use case to serve API endpoints from existing project written in Express app.

I can now seamlesssly make transition to cloud functions, and that is exactly what I am looking for!

It's simple to get the existing Express app up and running with minimal changes of code, not to mention that it's also easy to get started and deploy with Cloud Functions.



Only a few things to take note:

  1. Development without hot reload.

    As I am developing with the firebase emulators, I noticed that file changes saved are not reflected without restarting the emulators. There might be an option in the CLI that can be enabled that I didn't know of.

  2. Managing environment variables for staging and production are not what I am used to

    For sensitive information, I used Google Secret Manager to store the key-value pair secret. It is more secure than storing in .env in Cloud Functions, however I can't use the same environment variable name for different environment. For example, I now need to have MY_SECRET and MY_SECRET_STAGING for different environment. I am looking for other ways to do it in the future but I am now settled with it.

    It is suggested that I should create another cloud functions project to serve staging environment, but in my use case, I use another Express app instead, and it works well for my scenario.


I didn't spent a lot of time this time exploring how things should be done in Firebase Cloud Functions. However, I am happy that I don't have to spend more time to get my existing project up and running again.

Firebase Cloud Functions saved me from having to rewrite the app, and I am happy about it. Do check that out for your next projects.

Cheers.