Skip to content

Instantly share code, notes, and snippets.

@NickNaso
Forked from gabrielschulhof/binding.gyp
Created January 16, 2018 21:15
Show Gist options
  • Save NickNaso/20f3c9f2c0cbde16edc19c0dc68d9f0e to your computer and use it in GitHub Desktop.
Save NickNaso/20f3c9f2c0cbde16edc19c0dc68d9f0e to your computer and use it in GitHub Desktop.
{
"targets": [
{
"target_name": "example_addon",
"sources": [ "example_addon.c" ],
"include_dirs": [ "<!@(node -p \"require('node-addon-api').include\")" ],
"dependencies": [ "<!@(node -p \"require('node-addon-api').gyp\")" ]
}
]
}
#include <node_api.h>
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_value value;
status = napi_create_uint32(env, 42, &value);
if (status != napi_ok) {
napi_fatal_error("Init", NAPI_AUTO_LENGTH, "Failed to create number",
NAPI_AUTO_LENGTH);
}
status = napi_set_named_property(env, exports, "answer", value);
if (status != napi_ok) {
napi_fatal_error("Init", NAPI_AUTO_LENGTH, "Failed to assign property",
NAPI_AUTO_LENGTH);
}
return exports;
}
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
module.exports = require('./build/Release/example_addon.node');
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "node-gyp rebuild"
},
"author": "",
"license": "Apache-2.0",
"gypfile": true,
"dependencies": {
"node-addon-api": "^1.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment