Creating a Dependency for a Node.js Function
You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, the dynamic link library may not be found due to the differences between underlying dependency libraries.
Constraints
If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.
Setting Up the EulerOS Environment
You are advised to create function dependencies in EulerOS. EulerOS is an enterprise-grade Linux OS based on open-source technology. It features high security, scalability, and performance, meeting customers' requirements for IT infrastructure and cloud computing services.
You can set up the Huawei Cloud EulerOS environment using the following methods:
- Buy a EulerOS ECS on Huawei Cloud by referring to Purchasing and Logging In to a Linux ECS. On the Configure Basic Settings page, select Public Image, and select Huawei Cloud EulerOS and an image version.
- Download the EulerOS image, and use virtualization software to set up the EulerOS VM on a local PC.
Creating a Dependency for a Node.js Function
Before creating a dependency, ensure that Node.js matching the function runtime has been installed in the environment. The following uses Node.js 20.15 as an example to describe how to create a MySQL dependency package.
- Run the following command to install the MySQL dependency package.
npm install mysql --save
The node_modules folder is generated under the current directory.
- Run the following command to generate the ZIP dependency package.
zip -rq mysql-node20.15.zip node_modules
To package multiple dependencies, follow the steps below:
- Create a package.json file with the following content: Change the dependency version as required.
{ "name": "test", "version": "1.0.0", "dependencies": { "redis": "~2.8.0", "mysql": "~2.17.1" } } - Run the following command.
npm install --save
- Compress node_modules into a ZIP package. This generates a dependency that contains both MySQL and Redis.
zip -rq mysql-node20.15.zip node_modules
Helpful Links
- For details about how to use Node.js to develop an event function, see Developing a Node.js Event Function.
- For details about how to use Node.js to develop an HTTP function, see Developing an HTTP Function Using Node.js.
- For details about how to create a dependency package for a Node.js function, see Creating a Dependency for a Node.js Function.
- For more information about function development, such as the supported runtimes, trigger events, function project packaging specifications, and DLL referencing, see Function Development Overview.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot