Skip to main content

tcb fn run

Run and debug cloud functions locally without deploying them.

Node.js only

tcb fn run currently supports only the Node.js runtime. To run function-type CloudRun services locally, see CloudRun local run.

Usage​

tcb fn run [options]

Two ways to locate a function:

  • --path: point to the function directory and run with default configuration. No cloudbaserc.json required.
  • --name: read the matching function configuration from cloudbaserc.json (handler, envVariables, params) and run it.

Flags​

FlagRequiredDescriptionDefault
--path <path>One of --path or --nameFunction directory, run with default configuration—
--name <name>One of --path or --nameFunction name, configuration read from cloudbaserc.json—
--params <params>NoInvocation parameters as a JSON string—
--debugNoStart in Node Inspector mode—
--port <port>NoDebug listen port9229

Examples​

Run by path​

The directory must contain index.js exporting a main method.

# Run ./functions/app with default configuration
tcb fn run --path ./functions/app

Run by name​

The project directory must contain cloudbaserc.json with the function declared in functions.

tcb fn run --name app

The function runs with handler, envVariables, and params from the configuration file. See Function Configuration.

Pass parameters​

tcb fn run --name app --params '{"userId": "123", "action": "query"}'

When both the configuration file and the command line set params, the command line wins.

Start debug mode​

# Use the default port 9229
tcb fn run --path ./functions/app --debug

# Use a custom debug port
tcb fn run --path ./functions/app --debug --port 9230

Connect Chrome DevTools or VS Code to the port to set breakpoints.

Notes​

  • Only Node.js is supported. Python, Java, Go, PHP, and other runtimes cannot run locally through tcb fn run.
  • With --path, the directory must contain index.js exporting a main method.
  • With --name, the entry file and function name are resolved from handler in cloudbaserc.json, which defaults to index.main.
  • When logged in, the runtime injects TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, and TENCENTCLOUD_SESSIONTOKEN, so the function can call CloudBase resources directly. Without login these variables are absent and such calls may fail.