This project demonstrates how to use N-API with node_api.h to call a C function (addition) from JavaScript.
native-addon/
├── addon.c
├── binding.gyp
├── index.js
├── package.json
├── package-lock.json
└── README.md
-
addon.c : N-API wrapper that contains the native C function int add(int a, int b) and bridges add() to JavaScript.
-
index.js : JavaScript file that uses the native addon.
-
binding.gyp : Build configuration for node-gyp.
npm install -g node-gyp
npm install
node-gyp configure
node-gyp build
The compiled addon will be created in the build/Release/ folder.
node index.js