1# Dynamically Loading a Native Module in Synchronous Mode 2 3The **loadNativeModule** API is used to dynamically load a native module in synchronous mode. It can be used to load a module only when the module needs to be used, shortening the cold start time. However, the API call involves the loading the .so file. You need to evaluate the impact caused by the .so file loading. 4 5## API Description 6 7```js 8loadNativeModule(moduleName: string): Object; 9``` 10 11| Parameter | Description | 12| :------------- | :----------------------------- | 13| moduleName | Name of the module to load. | 14 15> **NOTE** 16> **moduleName** must be set to the module name configured in the **module.json5** file in the HAP to which the module to load belongs. 17> 18> **loadNativeModule** can be used only to load modules in the main thread. 19> 20> Dependencies must be configured for the API call regardless of whether the input parameter is a constant string or variable expression. 21 22## Supported Scenarios 23 24| Scenario | Example | 25| :------------- | :----------------------------- | 26| System library module | Load **@ohos.** or **@system.**. | 27| Native module in an application| Load **libNativeLibrary.so**.| 28 29## Example 30 31- **Loading a system library module to a HAP** 32 33```js 34let hilog: ESObject = loadNativeModule("@ohos.hilog"); 35hilog.info(0, "testTag", "loadNativeModule ohos.hilog success"); 36``` 37 38- **Loading a native library to a HAP** 39 40The **index.d.ts** file of **libentry.so** is as follows: 41 42```javascript 43//index.d.ts 44export const add: (a: number, b: number) => number; 45``` 46 471. Configure dependencies in the **oh-package.json5** file. 48 49```json 50{ 51 "dependencies": { 52 "libentry.so": "file:../src/main/cpp/types/libentry" 53 } 54} 55``` 56 572. Configure the source package in **build-profile.json5**. 58 59```json 60{ 61 "buildOption" : { 62 "arkOptions" : { 63 "runtimeOnly" : { 64 "packages": [ 65 "libentry.so" 66 ] 67 } 68 } 69 } 70} 71``` 72 733. Use **loadNativeModule** to load **libentry.so** and call the **add** function. 74 75```js 76let module: ESObject = loadNativeModule("libentry.so"); 77let sum: number = module.add(1, 2); 78``` 79