1e41f4b71Sopenharmony_ci# Loading a Module Using Node-API
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciYou can use **napi_load_module_with_info** to load modules. After a module is loaded, you can use **napi_get_property** to obtain the variables exported by the module or use **napi_get_named_property** to obtain the functions exported by the module. The **napi_load_module_with_info** API can be used in a [newly created ArkTS runtime environment](use-napi-ark-runtime.md).
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Function Description
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci```cpp
8e41f4b71Sopenharmony_cinapi_status napi_load_module_with_info(napi_env env,
9e41f4b71Sopenharmony_ci                                       const char* path,
10e41f4b71Sopenharmony_ci                                       const char* module_info,
11e41f4b71Sopenharmony_ci                                       napi_value* result);
12e41f4b71Sopenharmony_ci```
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci| Parameter           | Description         |
15e41f4b71Sopenharmony_ci| :------------- | :----------------------------- |
16e41f4b71Sopenharmony_ci| env            | Current VM environment.      |
17e41f4b71Sopenharmony_ci| path          | Path of the file or name of the module to load.         |
18e41f4b71Sopenharmony_ci| module_info   | Path composed of **bundleName** and **moduleName**.      |
19e41f4b71Sopenharmony_ci| result         | Module loaded.         |
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci> **NOTE**
22e41f4b71Sopenharmony_ci> 
23e41f4b71Sopenharmony_ci> - **bundleName** indicates the project name configured in **AppScope/app.json5**.
24e41f4b71Sopenharmony_ci> - **moduleName** indicates the module name configured in **module.json5** in the HAP of the module to be loaded.
25e41f4b71Sopenharmony_ci> - You can also use [napi_load_module](use-napi-load-module.md) to load modules. However, **napi_load_module** is limited to loading modules in the main thread only.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## When to Use
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Scenario           | Description          | Description                        |
30e41f4b71Sopenharmony_ci| :------------- | :----------------------------- | :--------------------------- |
31e41f4b71Sopenharmony_ci| Local project module  | Load a module from a local project file using the relative path to a HAP.      | The file paths must start with **moduleName**.            |
32e41f4b71Sopenharmony_ci| Local HAR module  | Load a HAR module to a HAP.          | -                            |
33e41f4b71Sopenharmony_ci| Remote HAR module        | Load a remote HAR module to a HAP.       | -                            |
34e41f4b71Sopenharmony_ci| Remote ohpm module        | Load an ohpm package to a HAP.           | -                            |
35e41f4b71Sopenharmony_ci| API        |    Load @ohos. or @system. to a HAP.         | -                            |
36e41f4b71Sopenharmony_ci| Native library module  | Load **libNativeLibrary.so** to a HAP.| -                            |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci> **NOTE**
39e41f4b71Sopenharmony_ci>
40e41f4b71Sopenharmony_ci> - The "module" to be loaded is the entry file, generally **index.ets/ts**, of the module.
41e41f4b71Sopenharmony_ci> - To load a HAR to another HAR, ensure that **module_info** is correct. The value of **moduleName** must be that of the HAP.
42e41f4b71Sopenharmony_ci> - If a third-party package is directly or indirectly used in a HAP/HSP and the third-party package uses **napi_load_module_with_info** to load other module, for example, module A, the dependency of module A must also be added to the HAP/HSP.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci## How to Use
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci- **Loading a module from a local project file to a HAP**
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciLoad a module from a file as shown in the following ArkTS code.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci```javascript
51e41f4b71Sopenharmony_ci//./src/main/ets/Test.ets
52e41f4b71Sopenharmony_cilet value = 123;
53e41f4b71Sopenharmony_cifunction test() {
54e41f4b71Sopenharmony_ci  console.log("Hello OpenHarmony");
55e41f4b71Sopenharmony_ci}
56e41f4b71Sopenharmony_ciexport {value, test};
57e41f4b71Sopenharmony_ci```
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci1. Add the following to the **build-profile.json5** file of the project.
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci```json
62e41f4b71Sopenharmony_ci{
63e41f4b71Sopenharmony_ci    "buildOption" : {
64e41f4b71Sopenharmony_ci        "arkOptions" : {
65e41f4b71Sopenharmony_ci            "runtimeOnly" : {
66e41f4b71Sopenharmony_ci                "sources": [
67e41f4b71Sopenharmony_ci                    "./src/main/ets/Test.ets"
68e41f4b71Sopenharmony_ci                ]
69e41f4b71Sopenharmony_ci            }
70e41f4b71Sopenharmony_ci        }
71e41f4b71Sopenharmony_ci    }
72e41f4b71Sopenharmony_ci}
73e41f4b71Sopenharmony_ci```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci2. Use **napi_load_module_with_info** to load the **Test.ets** file, call the **test()** function, and obtain the variable values.
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci> **NOTE**
78e41f4b71Sopenharmony_ci>
79e41f4b71Sopenharmony_ci> If **seNormalizedOHMUrl** is enabled (the **useNormalizedOHMUrl** field of **strictMode** in the application's **build-profile.json5** file at the same level as **entry** in the project directory is set to **true**), **bundleName** does not affect the loading logic when a HAP module is loaded. The corresponding HAP in the process is intelligently indexed based on the module name. For example, the module can be successfully loaded if **bundleName** is set to **com.example.application1** while the actual bundle name of the project is **com.example.application**.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci```cpp
82e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
83e41f4b71Sopenharmony_ci    napi_value result;
84e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load the module from the Test.ets file.
85e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "entry/src/main/ets/Test", "com.example.application/entry", &result);
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci    napi_value testFn;
88e41f4b71Sopenharmony_ci    // 2. Call napi_get_named_property to obtain the test function.
89e41f4b71Sopenharmony_ci    napi_get_named_property(env, result, "test", &testFn);
90e41f4b71Sopenharmony_ci    // 3. Call napi_call_function to call the test function.
91e41f4b71Sopenharmony_ci    napi_call_function(env, result, testFn, 0, nullptr, nullptr);
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci    napi_value value;
94e41f4b71Sopenharmony_ci    napi_value key;
95e41f4b71Sopenharmony_ci    std::string keyStr = "value";
96e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key);
97e41f4b71Sopenharmony_ci    // 4. Call napi_get_property to obtain a variable value.
98e41f4b71Sopenharmony_ci    napi_get_property(env, result, key, &value);
99e41f4b71Sopenharmony_ci    return result;
100e41f4b71Sopenharmony_ci}
101e41f4b71Sopenharmony_ci```
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci- **Loading a HAR module to a HAP**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ciThe **Index.ets** file in the HAR package is as follows:
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci```javascript
108e41f4b71Sopenharmony_ci//library Index.ets
109e41f4b71Sopenharmony_cilet value = 123;
110e41f4b71Sopenharmony_cifunction test() {
111e41f4b71Sopenharmony_ci  console.log("Hello OpenHarmony");
112e41f4b71Sopenharmony_ci}
113e41f4b71Sopenharmony_ciexport {value, test};
114e41f4b71Sopenharmony_ci```
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci1. Configure dependencies in the **oh-package.json5** file.
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci```json
119e41f4b71Sopenharmony_ci{
120e41f4b71Sopenharmony_ci    "dependencies": {
121e41f4b71Sopenharmony_ci        "library": "file:../library"
122e41f4b71Sopenharmony_ci    }
123e41f4b71Sopenharmony_ci}
124e41f4b71Sopenharmony_ci```
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci2. Configure the source package in **build-profile.json5**.
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci```json
129e41f4b71Sopenharmony_ci{
130e41f4b71Sopenharmony_ci    "buildOption" : {
131e41f4b71Sopenharmony_ci        "arkOptions" : {
132e41f4b71Sopenharmony_ci            "runtimeOnly" : {
133e41f4b71Sopenharmony_ci                "packages": [
134e41f4b71Sopenharmony_ci                    "library"
135e41f4b71Sopenharmony_ci                ]
136e41f4b71Sopenharmony_ci            }
137e41f4b71Sopenharmony_ci        }
138e41f4b71Sopenharmony_ci    }
139e41f4b71Sopenharmony_ci}
140e41f4b71Sopenharmony_ci```
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci3. Use **napi_load_module_with_info** to load **library**, call the **test** function, and obtain the variable values.
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci```cpp
145e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
146e41f4b71Sopenharmony_ci    napi_value result;
147e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load library.
148e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "library", "com.example.application/entry", &result);
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci    napi_value testFn;
151e41f4b71Sopenharmony_ci    // 2. Call napi_get_named_property to obtain the test function.
152e41f4b71Sopenharmony_ci    napi_get_named_property(env, result, "test", &testFn);
153e41f4b71Sopenharmony_ci    // 3. Call napi_call_function to call the test function.
154e41f4b71Sopenharmony_ci    napi_call_function(env, result, testFn, 0, nullptr, nullptr);
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci    napi_value value;
157e41f4b71Sopenharmony_ci    napi_value key;
158e41f4b71Sopenharmony_ci    std::string keyStr = "value";
159e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key);
160e41f4b71Sopenharmony_ci    // 4. Call napi_get_property to obtain a variable value.
161e41f4b71Sopenharmony_ci    napi_get_property(env, result, key, &value);
162e41f4b71Sopenharmony_ci    return result;
163e41f4b71Sopenharmony_ci}
164e41f4b71Sopenharmony_ci```
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci- **Loading a remote HAR module to a HAP**
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci1. Configure dependencies in the **oh-package.json5** file.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```json
171e41f4b71Sopenharmony_ci{
172e41f4b71Sopenharmony_ci    "dependencies": {
173e41f4b71Sopenharmony_ci        "@ohos/hypium": "1.0.16"
174e41f4b71Sopenharmony_ci    }
175e41f4b71Sopenharmony_ci}
176e41f4b71Sopenharmony_ci```
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci2. Configure the source package in **build-profile.json5**.
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci```json
181e41f4b71Sopenharmony_ci{
182e41f4b71Sopenharmony_ci    "buildOption" : {
183e41f4b71Sopenharmony_ci        "arkOptions" : {
184e41f4b71Sopenharmony_ci            "runtimeOnly" : {
185e41f4b71Sopenharmony_ci                "packages": [
186e41f4b71Sopenharmony_ci                    "@ohos/hypium"
187e41f4b71Sopenharmony_ci                ]
188e41f4b71Sopenharmony_ci            }
189e41f4b71Sopenharmony_ci        }
190e41f4b71Sopenharmony_ci    }
191e41f4b71Sopenharmony_ci}
192e41f4b71Sopenharmony_ci```
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci3. Use **napi_load_module_with_info** to load **@ohos/hypium** and obtain the default variable.
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci```cpp
197e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
198e41f4b71Sopenharmony_ci    napi_value result;
199e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load @ohos/hypium.
200e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "@ohos/hypium", "com.example.application/entry", &result);
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci    napi_value key;
203e41f4b71Sopenharmony_ci    std::string keyStr = "DEFAULT";
204e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key);
205e41f4b71Sopenharmony_ci    // 2. Call napi_get_property to obtain the default variable.
206e41f4b71Sopenharmony_ci    napi_value defaultValue;
207e41f4b71Sopenharmony_ci    napi_get_property(env, result, key, &defaultValue);
208e41f4b71Sopenharmony_ci    return result;
209e41f4b71Sopenharmony_ci}
210e41f4b71Sopenharmony_ci```
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci- **Loading an ohpm package to a HAP**
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci1. Configure dependencies in the **oh-package.json5** file.
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci```json
217e41f4b71Sopenharmony_ci{
218e41f4b71Sopenharmony_ci    "dependencies": {
219e41f4b71Sopenharmony_ci        "json5": "^2.2.3"
220e41f4b71Sopenharmony_ci    }
221e41f4b71Sopenharmony_ci}
222e41f4b71Sopenharmony_ci```
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci2. Configure the source package in **build-profile.json5**.
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci```json
227e41f4b71Sopenharmony_ci{
228e41f4b71Sopenharmony_ci    "buildOption" : {
229e41f4b71Sopenharmony_ci        "arkOptions" : {
230e41f4b71Sopenharmony_ci            "runtimeOnly" : {
231e41f4b71Sopenharmony_ci                "packages": [
232e41f4b71Sopenharmony_ci                    "json5"
233e41f4b71Sopenharmony_ci                ]
234e41f4b71Sopenharmony_ci            }
235e41f4b71Sopenharmony_ci        }
236e41f4b71Sopenharmony_ci    }
237e41f4b71Sopenharmony_ci}
238e41f4b71Sopenharmony_ci```
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci3. Use **napi_load_module_with_info** to load **json5** and call the **stringify** function.
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci```cpp
243e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
244e41f4b71Sopenharmony_ci    napi_value result;
245e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load json5.
246e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "json5", "com.example.application/entry", &result);
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci    napi_value key;
249e41f4b71Sopenharmony_ci    std::string keyStr = "default";
250e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key);
251e41f4b71Sopenharmony_ci    // 2. Call napi_get_property to obtain the default object.
252e41f4b71Sopenharmony_ci    napi_value defaultValue;
253e41f4b71Sopenharmony_ci    napi_get_property(env, result, key, &defaultValue);
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci    napi_value stringifyFn;
256e41f4b71Sopenharmony_ci    // 3. Call napi_get_named_property to obtain the stringify function.
257e41f4b71Sopenharmony_ci    napi_get_named_property(env, defaultValue, "stringify", &stringifyFn);
258e41f4b71Sopenharmony_ci    // 4. Use napi_call_function to call the stringify function.
259e41f4b71Sopenharmony_ci    napi_value argStr;
260e41f4b71Sopenharmony_ci    std::string text = "call json5 stringify";
261e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, text.c_str(), text.size(), &argStr);
262e41f4b71Sopenharmony_ci    napi_value args[1] = {argStr};
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci    napi_value returnValue;
265e41f4b71Sopenharmony_ci    napi_call_function(env, defaultValue, stringifyFn, 1, args, &returnValue);
266e41f4b71Sopenharmony_ci    return result;
267e41f4b71Sopenharmony_ci}
268e41f4b71Sopenharmony_ci```
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci- **Loading an API module to a HAP**
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci```cpp
273e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
274e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load the module @ohos.hilog.
275e41f4b71Sopenharmony_ci    napi_value result;
276e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "@ohos.hilog", nullptr, &result);
277e41f4b71Sopenharmony_ci    
278e41f4b71Sopenharmony_ci    // 2. Call napi_get_named_property to obtain the info function.
279e41f4b71Sopenharmony_ci    napi_value infoFn;
280e41f4b71Sopenharmony_ci    napi_get_named_property(env, result, "info", &infoFn);
281e41f4b71Sopenharmony_ci    
282e41f4b71Sopenharmony_ci    napi_value tag;
283e41f4b71Sopenharmony_ci    std::string formatStr = "test";
284e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, formatStr.c_str(), formatStr.size(), &tag);
285e41f4b71Sopenharmony_ci    
286e41f4b71Sopenharmony_ci    napi_value outputString;
287e41f4b71Sopenharmony_ci    std::string str = "Hello OpenHarmony";
288e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, str.c_str(), str.size(), &outputString);
289e41f4b71Sopenharmony_ci    
290e41f4b71Sopenharmony_ci    napi_value flag;
291e41f4b71Sopenharmony_ci    napi_create_int32(env, 0, &flag);
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci    napi_value args[3] = {flag, tag, outputString};
294e41f4b71Sopenharmony_ci    // 3. Use napi_call_function to call the info function.
295e41f4b71Sopenharmony_ci    napi_call_function(env, result, infoFn, 3, args, nullptr);
296e41f4b71Sopenharmony_ci    return result;
297e41f4b71Sopenharmony_ci}
298e41f4b71Sopenharmony_ci```
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci- **Loading a native library to a HAP**
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ciThe **index.d.ts** file of **libentry.so** is as follows:
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci```javascript
305e41f4b71Sopenharmony_ci// index.d.ts
306e41f4b71Sopenharmony_ciexport const add: (a: number, b: number) => number;
307e41f4b71Sopenharmony_ci```
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci1. Configure dependencies in the **oh-package.json5** file.
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci```json
312e41f4b71Sopenharmony_ci{
313e41f4b71Sopenharmony_ci    "dependencies": {
314e41f4b71Sopenharmony_ci        "libentry.so": "file:../src/main/cpp/types/libentry"
315e41f4b71Sopenharmony_ci    }
316e41f4b71Sopenharmony_ci}
317e41f4b71Sopenharmony_ci```
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci2. Configure the source package in **build-profile.json5**.
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci```json
322e41f4b71Sopenharmony_ci{
323e41f4b71Sopenharmony_ci    "buildOption" : {
324e41f4b71Sopenharmony_ci        "arkOptions" : {
325e41f4b71Sopenharmony_ci            "runtimeOnly" : {
326e41f4b71Sopenharmony_ci                "packages": [
327e41f4b71Sopenharmony_ci                    "libentry.so"
328e41f4b71Sopenharmony_ci                ]
329e41f4b71Sopenharmony_ci            }
330e41f4b71Sopenharmony_ci        }
331e41f4b71Sopenharmony_ci    }
332e41f4b71Sopenharmony_ci}
333e41f4b71Sopenharmony_ci```
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci3. Use **napi_load_module_with_info** to load **libentry.so** and call the **add** function.
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci```cpp
338e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
339e41f4b71Sopenharmony_ci    napi_value result;
340e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load libentry.so.
341e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "libentry.so", "com.example.application/entry", &result);
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci    napi_value addFn;
344e41f4b71Sopenharmony_ci    // 2. Call napi_get_named_property to obtain the add function.
345e41f4b71Sopenharmony_ci    napi_get_named_property(env, result, "add", &addFn);
346e41f4b71Sopenharmony_ci    
347e41f4b71Sopenharmony_ci    napi_value a;
348e41f4b71Sopenharmony_ci    napi_value b;
349e41f4b71Sopenharmony_ci    napi_create_int32(env, 2, &a);
350e41f4b71Sopenharmony_ci    napi_create_int32(env, 3, &b);
351e41f4b71Sopenharmony_ci    napi_value args[2] = {a, b};
352e41f4b71Sopenharmony_ci    // 3. Use napi_call_function to call the add function.
353e41f4b71Sopenharmony_ci    napi_value returnValue;
354e41f4b71Sopenharmony_ci    napi_call_function(env, result, addFn, 2, args, &returnValue);
355e41f4b71Sopenharmony_ci    return result;
356e41f4b71Sopenharmony_ci}
357e41f4b71Sopenharmony_ci```
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci- **Loading a HAR module to a HAR**
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ciLoad **har2** to **har1**. The **Index.ets** file of **har2** is as follows:
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci```javascript
364e41f4b71Sopenharmony_ci//har2 Index.ets
365e41f4b71Sopenharmony_cilet value = 123;
366e41f4b71Sopenharmony_cifunction test() {
367e41f4b71Sopenharmony_ci  console.log("Hello OpenHarmony");
368e41f4b71Sopenharmony_ci}
369e41f4b71Sopenharmony_ciexport {value, test};
370e41f4b71Sopenharmony_ci```
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci1. Configure **dependencies** in the **oh-package.json5** file of **har1**.
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci```json
375e41f4b71Sopenharmony_ci{
376e41f4b71Sopenharmony_ci    "dependencies": {
377e41f4b71Sopenharmony_ci        "har2": "file:../har2"
378e41f4b71Sopenharmony_ci    }
379e41f4b71Sopenharmony_ci}
380e41f4b71Sopenharmony_ci```
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci2. Configure the source package in the **build-profile.json5** file of **har1**.
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci```json
385e41f4b71Sopenharmony_ci{
386e41f4b71Sopenharmony_ci    "buildOption" : {
387e41f4b71Sopenharmony_ci        "arkOptions" : {
388e41f4b71Sopenharmony_ci            "runtimeOnly" : {
389e41f4b71Sopenharmony_ci                "packages": [
390e41f4b71Sopenharmony_ci                    "har2"
391e41f4b71Sopenharmony_ci                ]
392e41f4b71Sopenharmony_ci            }
393e41f4b71Sopenharmony_ci        }
394e41f4b71Sopenharmony_ci    }
395e41f4b71Sopenharmony_ci}
396e41f4b71Sopenharmony_ci```
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci3. In **har1**, use **napi_load_module_with_info** to load **har2**, call the **test** function, and obtain the variable value.
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci```cpp
401e41f4b71Sopenharmony_cistatic napi_value loadModule(napi_env env, napi_callback_info info) {
402e41f4b71Sopenharmony_ci    napi_value result;
403e41f4b71Sopenharmony_ci    // 1. Call napi_load_module_with_info to load har2. Note that moduleName is that of the HAP where the module is located.
404e41f4b71Sopenharmony_ci    napi_status status = napi_load_module_with_info(env, "har2", "com.example.application/entry", &result);
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci    napi_value testFn;
407e41f4b71Sopenharmony_ci    // 2. Call napi_get_named_property to obtain the test function.
408e41f4b71Sopenharmony_ci    napi_get_named_property(env, result, "test", &testFn);
409e41f4b71Sopenharmony_ci    // 3. Call napi_call_function to call the test function.
410e41f4b71Sopenharmony_ci    napi_call_function(env, result, testFn, 0, nullptr, nullptr);
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci    napi_value value;
413e41f4b71Sopenharmony_ci    napi_value key;
414e41f4b71Sopenharmony_ci    std::string keyStr = "value";
415e41f4b71Sopenharmony_ci    napi_create_string_utf8(env, keyStr.c_str(), keyStr.size(), &key);
416e41f4b71Sopenharmony_ci    // 4. Call napi_get_property to obtain a variable value.
417e41f4b71Sopenharmony_ci    napi_get_property(env, result, key, &value);
418e41f4b71Sopenharmony_ci    return result;
419e41f4b71Sopenharmony_ci}
420e41f4b71Sopenharmony_ci```
421e41f4b71Sopenharmony_ci<!--no_check-->