nodejs / node-addon-examples

Node.js C++ addon examples from http://nodejs.org/docs/latest/api/addons.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node.js C++ Addon Documentation

ann--b opened this issue · comments

The above documentation refers the reader to this repo for the examples. But the first hello.cc example in the documentation doesn't match the 1_hello_world/node-addon-api example. The docs include <node.h> and the repo cc file includes <napi.h>. The repo file include line was added 5 years ago. I don't know which code is the most recent. I'm about to start reading the Node API Resource so maybe I can figure it out.

I think the Node.js documentation is using Node-API which is built into Node, and these examples are using the node-addon-api package. The Node API Resource did mention that not using this package will require additional coding, so that's why the code doesn't match.

Hi @ann--b,
Node-API is a C ABI stable API exported from the Node.js core and its documentation is in the core documentation https://nodejs.org/docs/latest/api/n-api.html. node-addon-api is a C++ wrapper around Node-API api.
The Node Addons Examples repo contains some examples written in nan, Node-API and node-addon-api if you need the example that use Node-API you should see in the napi folder.

Thank you @NickNaso. As a beginner I don't think I'm ready for the Node API and the core documentation. I will study the node-addon-api examples for now.