0

In my NodeJS application I have few common code that could be used by many other Cloud Functions in GCP. But I don't know how can I share these code among multiple apps to reduce code redundancy.
I thought of keeping these files in GCS and use that file location in NodeJS but I am sure it won't support this way as I may need to download this file before using it.
So, is there any better way to accomplish my idea?

shary.sharath
  • 649
  • 2
  • 14
  • 29

1 Answers1

0

You have several way to solve that.

At deployment time (with your CI/CD, on Cloud Build for instance) you can copy the common dependencies in the Cloud Functions code base and then deploy it. It's (it was) a common and usual way to share common code with Cloud Functions.

But, a more recent way is to use Artifact Registry to store your NodeJS modules. Then, in your cloud functions dependencies, reference that module in Artifact Registry to let Cloud Functions downloading it.

It's a better solution because you use standard code packaging and dependencies, it's private to your project (except if you open your registry publicly) and you haven't hack to do.

--

You can also switch to Cloud Run, where you control your container creation and download the file that you want. It's not Cloud Functions, but it's very similar (and it's my personal preference)

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76