Creating a Dependency
You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, an error may occur due to underlying dependent libraries. For example, the dynamic link library cannot be found.
- If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.
Creating a Dependency for a Node.js Function
Ensure that the corresponding Node.js version has been installed in the environment.
To install the MySQL dependency for a Node.js 8.10 function, run the following command:
npm install mysql --save
The node_modules folder is generated under the current directory.
- Linux OS
Run the following command to generate a ZIP package.
zip -rq mysql-node8.10.zip node_modules
The required dependency is generated.
To install multiple dependencies, create a package.json file first. For example, enter the following content into the package.json file and then run the following command:
{ "name": "test", "version": "1.0.0", "dependencies": { "redis": "~2.8.0", "mysql": "~2.17.1" } }
npm install --save
Do not run the CNPM command to generate Node.js dependencies.
Compress node_modules into a ZIP package. This generates a dependency that contains both MySQL and Redis.
For other Node.js versions, you can create dependencies in the way stated above.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.