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