HarmonyOS N-API Module Loading in Main Thread

Module Loading Overview The Node-API napi_load_module intreface enables module loading in the main thread. After loading, developers can retrieve exported properties using napi_get_property or access functions via napi_get_named_property. Supported scenarios include: Loading system modules (e.g., @ohos.hilog) Loading modules from ArkTS files ...

Posted on Fri, 31 Jul 2026 16:08:29 +0000 by himnbandit

HarmonyOS Node-API Lifecycle and Error Diagnosis Patterns

Distinguishing Lifetimes of napi_value and napi_ref napi_value instances are automatically tracked and retained within the current HandleScope. Explicit scope management is typically unnecessary—except in asynchronous completion callbacks (e.g., those invoked after uv_queue_work). In such contexts, a dedicated HandleScope must be establisehd b ...

Posted on Mon, 06 Jul 2026 17:48:21 +0000 by indian98476

Exporting C++ Class Objects via Node-API and Managing Their Lifecycle

Sample Project Source Code Analysis The sample project uses a Native C++ template with the Stage model. This analysis focuses on key implementation files for class object export and lifecycle management. Class Definition and Method Implementation NapiTest.h Header File #ifndef __NAPI_TEST_H__ #define __NAPI_TEST_H__ #include "napi/native_ ...

Posted on Thu, 11 Jun 2026 18:28:49 +0000 by itworks

Exporting NAPI Class Objects and Their Lifecycle Management (Part 1)

1. Exporting NAPI Class Objects OpenHarmony NAPI provides a way to "wrap" C++ classes and instances sothat JS applications can call constructors, methods, and access properties of those classes. Node.js Node-API also supports exporting class objects. 1.1. Flow of Exporting Class Objects via NAPI Define a JS class using napi_define_cl ...

Posted on Thu, 07 May 2026 14:48:49 +0000 by bubblocity