An Express app as a web service in Cloud Functions

If you want to avoid creating a Dockerfile, building the Docker image in Cloud Build and deploying it in Cloud Run, you can simply export an Express app as a function and deploy it with Cloud Functions.

Cloud Functions provides an Express wrapper (Functions Framework) and one of a number of pre-configured containers (e.g. "Node 10") to run the function inside.

If you've exported the app with exports.example = app, it's easy to test locally by running functions-framework --target=example.

You can set environment variables when running the functions-framework command, and if you've downloaded the credentials for the default service account as JSON, you can provide them here:

GOOGLE_APPLICATION_CREDENTIALS=service-account.json functions-framework --target=example

When you're ready, you can deploy the function:

gcloud functions deploy example --runtime nodejs10 --trigger-http --region $REGION

If you need to set any environment variables, it's easiest to do that in the Cloud Functions console, at the bottom of the "Edit" form.

There are a few downsides to using Cloud Functions instead of Cloud Run: