Frequently Asked Questions
What is the difference between
emnapi and native Node-API
emnapiis compiled to WebAssembly by Emscripten, while native Node-API is compiled to Node.js addon (
.nodeis operating system shared library) and can use operating system APIs.
emnapiis able to use the builtin
node-addon-apiout of box if the if the runtime support
When should I use
- You prefer Node-API, and you are more familiar with Node-API than
- You want to port your (or existing) Node.js addon written in Node-API to WebAssembly.
- You want your native module npm package to be installed smoothly by users without having to deal with node-gyp.
How to port existing Node.js addon written in Node-API
It is very difficult to port a native addon which has heavy use of operating system APIs (especially heavy use of
You can not use node-addon-api if the runtime does not support
- Checking if all APIs used in the addon are implemented in
emnapi. See API List.
- Checking runtime weak reference support by using emnapi_is_support_weakref before calling
- Checking if it is necessary to sync wasm memory according to ArrayBuffer Related API
- Writing CMakeLists. node-gyp is not supported.