Help Center/ FunctionGraph/ Developer Guide/ Node.js/ Creating a Dependency for a Node.js Function
Updated on 2025-12-10 GMT+08:00

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.

  1. Run the following command to install the MySQL dependency package.

    npm install mysql --save

    The node_modules folder is generated under the current directory.

  2. 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:

  1. 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"
    	}
    }

  2. Run the following command.

    npm install --save

  3. 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