# Managing Cloud Functions in Developer Tools

# Configuring Local Directory for Cloud Function

The project.config.json file can be used in the root directory of the project to define the cloudfunctionRoot field and specify an existing local directory as the local root directory of the cloud function.

# Cloud Function Operations

Right-click the root directory of the cloud function or the cloud function directory to open the right-click menu and complete the following operations:

  1. Check the current environment
  2. Switch environment
  3. Create Node.js cloud function
  4. Download the cloud functions list of the online environment
  5. Download the cloud function code of the online environment and overwrite the local code
  6. Compare local code with online environment code
  7. Upload and deploy the cloud function to the online environment

# Viewing and Switching Environment

Right-click the root directory of the cloud function. In the right-click menu, we can view and switch the current environment. All subsequent right-click operations are performed in this environment.

# Creating Node.js Cloud Function

Right-click the root directory of cloud function. In the right-click menu, we can choose to create a new Node.js cloud function. The Developer Tools creates the following directories and files locally, and meanwhile creates the corresponding cloud functions in the online environment:

  • Cloud function directory: A directory named after the cloud function that stores all the cloud function code.
  • index.js: An entry file of the cloud function. The entry function actually executed when the cloud function is called is the main method exported from index.jsv.
  • package.json: A npm package definition file, which defines the latest wx-server-sdk dependency by default.

After successful creation, the tools will prompt whether to immediately install the local dependency wx-server-sdk for the cloud function. If yes, the tools will open the terminal to execute npm install.

# Downloading Cloud Function List

Right-click the root directory of the cloud function. In the right-click menu, we can sync the list of cloud functions in the online environment to the local device. The Developer Tools creates cloud function directories locally according to the names of the cloud functions.

# Downloading Cloud Function

Right-click a cloud function directory to download the cloud function from the menu. The cloud function code will be downloaded to the specified directory.

# Uploading and Deploying

Right-click the cloud function directory. In the right-click menu, we can package the cloud function as a whole and then upload it to the online environment.

# More Settings

We can enter the immersive and interactive cloud function scenario from "More Settings" in the right-click menu. In this scenario, all the above cloud function operations can be performed. Press ctrl in the cloud directory to select multiple items for batch operations.

In the next chapter, we will learn how to perform tests and view logs and monitoring data while developing cloud functions.

点击咨询小助手