Package detail

gcx

JustinBeckwith10.6kMIT3.0.0

An API and CLI for deploying Google Cloud Functions in Node.js.

google, cloud, functions, serverless

readme

gcx

An API and CLI for deploying and calling Google Cloud Functions in Node.js.

NPM Version Build Status) codecov Known Vulnerabilities semantic-release

Installation

$ npm install gcx

Command Line

gcx is a convenient way to deploy and call Google Cloud Functions. To use as a command line application:

$ npm install --save-dev gcx

Then from your package.json, it's super easy to add a deploy script:

"scripts": {
  "deploy": "gcx deploy my-awesome-function"
}

Deploy positional arguments

FUNCTION_NAME

ID of the function or fully qualified identifier for the function. This positional must be specified if any of the other arguments in this group are specified.

Flags

--description

User-provided description of a function.

--region

The cloud region for the function. Defaults to us-central1.

--runtime

The runtime in which to run the function. Defaults to nodejs14.

  • nodejs10: Node.js 10
  • nodejs12: Node.js 12
  • nodejs14: Node.js 14
  • python37: Python 3.7
  • python38: Python 3.8
  • python39: Python 3.9
  • go111: Go 1.11
  • go113: Go 1.13
  • java11: Java 11
  • dotnet3: .NET Framework 3
  • ruby26: Ruby 2.6
--retry

If specified, then the function will be retried in case of a failure.

--memory

Limit on the amount of memory the function can use. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB. By default, a new function is limited to 256MB of memory. When deploying an update to an existing function, the function will keep its old memory limit unless you specify this flag.

--project

Project Id of the GCP project.

--target-dir

The directory that contains the sources to be deployed. Defaults to the current working directory.

--trigger-bucket

Google Cloud Storage bucket name. Every change in files in this bucket will trigger function execution.

--trigger-http

Function will be assigned an endpoint, which you can view by using the describe command. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS.

--trigger-topic

Name of Pub/Sub topic. Every message published in this topic will trigger function execution with message contents passed as input data.

--trigger-event

Specifies which action should trigger the function. For a list of acceptable values, call gcloud functions event-types list.

--trigger-resource=RESOURCE

Specifies which resource from --trigger-event is being observed. E.g. if --trigger-event is providers/cloud.storage/eventTypes/object.change, --trigger-resource must be a bucket name. For a list of expected resources, call gcloud functions event-types list.

--timeout

The function execution timeout, e.g. 30s for 30 seconds. Defaults to original value for existing function or 60 seconds for new functions. Cannot be more than 540s.

--entryPoint

By default when a Google Cloud Function is triggered, it executes a JavaScript function with the same name. Or, if it cannot find a function with the same name, it executes a function named function. You can use this flag to override the default behavior, by specifying the name of a JavaScript function that will be executed when the Google Cloud Function is triggered.

--network

The VPC Network that this cloud function can connect to. It can be either the fully-qualified URI, or the short name of the network resource. If the short network name is used, the network must belong to the same project. Otherwise, it must belong to a project within the same organization. The format of this field is either projects/{project}/global/networks/{network} or {network}, where {project} is a project id where the network is defined, and {network} is the short name of the network.

--max-instances

The limit on the maximum number of function instances that may coexist at a given time. This feature is currently in alpha, available only for whitelisted users.

Examples

# Deploy a new function
$ gcx deploy myhook --runtime nodejs14 --trigger-http

# Update the same function with new source code
$ gcx deploy myhook

API

You can also use this as a regular old API.

const {call, deploy} = require('gcx');

async function main() {
  await deploy({
    name: 'my-fn-name',
    region: 'us-central1'
    ...
  });
  const res = await call({
    functionName: 'my-fn-name',
    ...
  });
}
main().catch(console.error);

Authentication

This library uses google-auth-library under the hood to provide authentication. That means you can authenticate a few ways.

Using a service account

One of the reasons this library exists is to provide a nodejs native deployment in environments where you don't want to have the Cloud SDK installed.

For this method, you'll need to create a service account, and download a key.

  1. In the GCP Console, go to the Create service account key page.
  2. From the Service account drop-down list, select New service account.
  3. In the Service account name field, enter a name.
  4. From the Role drop-down list, select Project > Owner.
  5. Click Create. A JSON file that contains your key downloads to your computer.
$ export GOOGLE_APPLICATION_CREDENTIALS="./keys.json"
$ gcx deploy YOUR_FUNCTION_NAME

Using application default credentials

If you plan on only using this from your machine, and you have the Google Cloud SDK installed, you can just use application default credentials like this:

$ gcloud auth login
$ gcloud auth application-default login
$ gcloud config set project 'YOUR-AWESOME-PROJECT'
$ gcx deploy YOUR_FUNCTION_NAME

License

MIT

changelog

Changelog

3.0.0 (2025-10-15)

⚠ BREAKING CHANGES

  • this requires nodejs 20 and up nao
  • require node 16 and up (#218)
  • This library now requires node.js 12 and up, and has been converted to ESM. Enjoy :)
  • Drops support for node.js 8

Features

  • Add data option to gcx.call. Fixes #27 (#26) (aa03e3c)
  • add a call method to the API (#15) (3ffc017)
  • add output during deployment in cli (e09eaf4)
  • add vpc connector field (#70) (6438f62)
  • complete function create (94423c5)
  • enable signed uploads to GCS (c9438ac)
  • generate a .gcloudignore if not present (56f2aee)
  • poll the operation and wait for completion (7730251)

Bug Fixes

  • accept project as well as projectId (7e5cb99)
  • accept name as a positional argument (eb5e6b5)
  • deps: downgrade node-fetch to 3.1.0 to address type errors (#199) (78a28cf)
  • deps: downgrade to fetch 2.x (#201) (c172235)
  • deps: update dependency archiver to v4 (#81) (68c7d94)
  • deps: update dependency archiver to v5 (#95) (5d71afa)
  • deps: update dependency archiver to v6 (#233) (79dfcd5)
  • deps: update dependency archiver to v7 (#262) (7eece63)
  • deps: update dependency gaxios to v5 (#177) (8058f13)
  • deps: update dependency globby to v10 (#43) (327ff55)
  • deps: update dependency globby to v11 (#64) (c7f0cef)
  • deps: update dependency globby to v14 (#249) (cc94f51)
  • deps: update dependency globby to v15 (#317) (4a3d566)
  • deps: update dependency globby to v9 (#5) (efad0c0)
  • deps: update dependency google-auth-library to v3 (#7) (21f7c94)
  • deps: update dependency googleapis to v100 (#175) (7e0e340)
  • deps: update dependency googleapis to v101 (#181) (edbcbb6)
  • deps: update dependency googleapis to v102 (#182) (d57d7bf)
  • deps: update dependency googleapis to v103 (#183) (5a489b5)
  • deps: update dependency googleapis to v104 (#184) (ca6ec2f)
  • deps: update dependency googleapis to v105 (#187) (939b9e4)
  • deps: update dependency googleapis to v109 (#195) (374c877)
  • deps: update dependency googleapis to v110 (#203) (8fb686d)
  • deps: update dependency googleapis to v111 (#207) (639eb13)
  • deps: update dependency googleapis to v113 (#209) (c256743)
  • deps: update dependency googleapis to v114 (#211) (d1dc919)
  • deps: update dependency googleapis to v117 (#217) (59c7158)
  • deps: update dependency googleapis to v118 (#219) (6ff920c)
  • deps: update dependency googleapis to v123 (#227) (5c4ed9e)
  • deps: update dependency googleapis to v126 (#232) (d0d9b94)
  • deps: update dependency googleapis to v128 (#241) (72e28ee)
  • deps: update dependency googleapis to v129 (#251) (b97ac22)
  • deps: update dependency googleapis to v130 (#255) (7c1451b)
  • deps: update dependency googleapis to v131 (#257) (fe43cc8)
  • deps: update dependency googleapis to v132 (#259) (c5d3495)
  • deps: update dependency googleapis to v133 (#261) (2c50fad)
  • deps: update dependency googleapis to v134 (#265) (2ea49aa)
  • deps: update dependency googleapis to v137 (#267) (baadd8c)
  • deps: update dependency googleapis to v139 (#270) (fae2148)
  • deps: update dependency googleapis to v140 (#271) (4571905)
  • deps: update dependency googleapis to v142 (#278) (0df4448)
  • deps: update dependency googleapis to v143 (#279) (5596354)
  • deps: update dependency googleapis to v144 (#280) (4db8d6c)
  • deps: update dependency googleapis to v36 (#3) (0c0d294)
  • deps: update dependency googleapis to v37 (#8) (1dc5bb5)
  • deps: update dependency googleapis to v38 (#24) (b7d27b3)
  • deps: update dependency googleapis to v39 (#25) (77f779e)
  • deps: update dependency googleapis to v40 (#36) (e2b82bb)
  • deps: update dependency googleapis to v42 (#45) (15112c3)
  • deps: update dependency googleapis to v43 (#49) (a8b1965)
  • deps: update dependency googleapis to v44 (#51) (20b3308)
  • deps: update dependency googleapis to v45 (#54) (70fbf7a)
  • deps: update dependency googleapis to v46 (#60) (1b4325c)
  • deps: update dependency googleapis to v47 (#67) (fe40413)
  • deps: update dependency googleapis to v48 (#78) (693b418)
  • deps: update dependency googleapis to v49 (#82) (325f042)
  • deps: update dependency googleapis to v50 (#84) (2a408c2)
  • deps: update dependency googleapis to v51 (#87) (29886d6)
  • deps: update dependency googleapis to v52 (#89) (5876605)
  • deps: update dependency googleapis to v54 (#93) (53fb61b)
  • deps: update dependency googleapis to v55 (#94) (a080a26)
  • deps: update dependency googleapis to v56 (#96) (0cedf9c)
  • deps: update dependency googleapis to v57 (#97) (cc0114c)
  • deps: update dependency googleapis to v58 (#98) (7fad795)
  • deps: update dependency googleapis to v59 (#100) (4c4713b)
  • deps: update dependency googleapis to v60 (#105) (bbb2196)
  • deps: update dependency googleapis to v61 (#108) (ed89158)
  • deps: update dependency googleapis to v62 (#110) (45004ea)
  • deps: update dependency googleapis to v63 (#112) (7a8632e)
  • deps: update dependency googleapis to v64 (#113) (4c8df95)
  • deps: update dependency googleapis to v65 (#114) (34ab277)
  • deps: update dependency googleapis to v66 (#117) (f9935fd)
  • deps: update dependency googleapis to v72 (#127) (4560c76)
  • deps: update dependency googleapis to v75 (#134) (fcedafc)
  • deps: update dependency googleapis to v76 (#137) (cba7ef6)
  • deps: update dependency googleapis to v77 (#138) (7831de5)
  • deps: update dependency googleapis to v78 (#139) (1145c47)
  • deps: update dependency googleapis to v79 (#140) (b5231ad)
  • deps: update dependency googleapis to v81 (#142) (207e3d1)
  • deps: update dependency googleapis to v82 (#143) (a09be35)
  • deps: update dependency googleapis to v84 (#147) (641da68)
  • deps: update dependency googleapis to v85 (#152) (e33d8f6)
  • deps: update dependency googleapis to v89 (#157) (982b467)
  • deps: update dependency googleapis to v91 (#160) (02ca397)
  • deps: update dependency googleapis to v92 (#162) (ab710d0)
  • deps: update dependency googleapis to v95 (#169) (9704e8d)
  • deps: update dependency googleapis to v96 (#170) (f8309fd)
  • deps: update dependency googleapis to v97 (#171) (96cf60c)
  • deps: update dependency googleapis to v98 (#172) (80f9e1d)
  • deps: update dependency googleapis to v99 (#173) (4995310)
  • deps: update dependency gts to v1 (#30) (d4bb290)
  • deps: update dependency meow to v11 (#196) (276c14a)
  • deps: update dependency meow to v12 (#220) (7cc3a52)
  • deps: update dependency meow to v13 (#252) (8151c46)
  • deps: update dependency meow to v14 (#313) (85bf1a3)
  • deps: update dependency meow to v7 (#85) (2592a18)
  • deps: update dependency meow to v8 (#111) (e770c7f)
  • deps: update dependency ora to v4 (#50) (02a3c2a)
  • deps: update dependency ora to v5 (#99) (1438446)
  • deps: update dependency ora to v7 (#229) (0b738df)
  • deps: update dependency ora to v8 (#253) (1d4e6ff)
  • deps: update dependency ora to v9 (#314) (c137577)
  • deps: update dependency update-notifier to v3 (#34) (988d226)
  • deps: update dependency update-notifier to v4 (#61) (2d871fe)
  • deps: update dependency update-notifier to v5 (#106) (28c5886)
  • deps: update dependency update-notifier to v6 (#185) (ece37b6)
  • deps: update dependency update-notifier to v7 (#246) (4927537)
  • deps: update dependency uuid to v10 (#272) (83b677d)
  • deps: update dependency uuid to v11 (#283) (949c4bd)
  • deps: update dependency uuid to v13 (#309) (e7d755d)
  • deps: update dependency uuid to v7 (#76) (c4e7c08)
  • deps: update dependency uuid to v8 (#83) (9ae9651)
  • deps: update dependency uuid to v9 (#192) (9fac655)
  • deps: update to meow 6.x (#74) (f3e8481)
  • deps: upgrade to the latest googleapis (#329) (3ca4665)
  • do not pass scopes to getClient (#46) (3083f45)
  • make an offering to the lint gods (46b4f2d)
  • migrate to esm (#174) (08ba9a1)
  • normalize gcx.call functionName param (#19) (ccb2762)
  • require node 16 and up (#218) (8737e7f)
  • run the linter (5c19c98)
  • types: remove ora and globby type packages (#22) (7c255cf)
  • update deps and move to xo (#244) (07b6d07)
  • update list of available runtimes and default (#128) (7ee4a68)
  • use default import for fetch (f3a6d1b)

Miscellaneous Chores

Build System