# Local Debugging of Cloud Function
Cloud Base provides a local debugging function for cloud functions to help developers debug cloud functions locally.
# Notes
- If the cloud function uses an npm module, you must install the appropriate dependency in the local cloud function directory to properly use the local debugging feature.
- By default, the system uses the Node.js provided by the Developer Tools. You can click the local debugging settings to make modifications.
# Runtime Environment Requirements
- Download and install the Developer Tools 1.02.1903211 or above. Click here to download.
# How to Use
1. Open local debugging interface
Developers can right-click the cloud function name to open the local debugging interface.
In the local debugging interface, click the corresponding cloud function and select Enable Local Debugging to debug the selected function locally.
When enabling local debugging, the system checks whether the dependency specified in package.json
has been installed locally for the cloud function. If not, you will receive a warning.
Once local debugging has been enabled for a cloud function, requests to the cloud function in the WeChat Developer Tools simulator and requests to this cloud function by other cloud functions for which local debugging has been enabled are automatically sent.
3. Debugging methods
The following request methods are supported for local cloud function debugging:
- Manual trigger: Enter the request parameters in the local debugging interface and initiate a call.
- Simulator trigger: A request to the cloud function is directly initiated in the IDE simulator.
In manual trigger mode, the system supports two simulation methods:
- Call from the Mini Program: In the cloud function, you can use
cloud.getWXContext()
to get WeChat context of the call, includingOPENID
and other fields. - Call from another cloud function: During the call, the cloud function does not contain WeChat context.
4. Template management
In manual trigger mode, developers must manually enter the request parameters. To facilitate template management, the system provides Save, Save As, and Delete features for templates.
In addition, when you save a template on the cloud function local debugging interface, the system creates the cloudfunctionTemplate
directory in the Mini Program's local code directory and creates a template file for this cloud function. You can manage this template by directly modifying the template file.