Install Node.js Dependencies
There are two ways to install Node.js dependencies for Cloud Function: local npm installation and online dependency installation.
Local npm Installation
Using npm to install third-party dependencies can only be done separately for each cloud function.
Enter the function code root directory and run the command in the terminal, for example, to install the request library.
npm install request --save
Successfully installed dependency files will be part of the cloud function code and manually uploaded to the cloud for use.
Online Dependency Installation
CloudBase provides cloud-based dependency installation, eliminating the need for manual dependency installation in the terminal.
- CloudBase Console
- CloudBase CLI Tool
Enter the CloudBase platform Function Editing Page, then click "Save and Install Dependencies" after editing online or uploading a zip code package.
installDependency:true
Example:
{
"envId": "xxx",
"functionRoot": "./functions",
"functions": [
{
"name": "app",
"config": {
// Timeout
"timeout": 5,
// Environment Variables
"envVariables": {
"key": "value"
},
"runtime": "Nodejs10.15",
"installDependency": true
},
// Input parameters when calling the cloud function
"params": {},
"handler": "index.main"
}
]
}