-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify Project Organization #282
Comments
I concur. I've been trying to build a binding for functionality that needs to be in C++. The main node docs start by using V8 directly, which I learned is a bad idea for multiple reasons. Then the N-API uses node_api.h which appears to be entirely a C API, but I'm running into all kinds of issues ("cannot create a handle without a HandleScope" woes), and now I'm learning everyone (for some definition of everyone) is using napi.h, which is for C++ but also called N-API and has very little documentation. I feel like I'm barely exaggerating when I say this could not be more confusing. It reminds me of this xkcd. |
Hi everyone, |
We do agree that documentation needs to be improved and as NickNaso mention we are working on that. If you have some specific wording that you think would improve things and where that wording would go to best clarify things please suggest it either here or through a PR. I do have in mind that we should merge the abi-stable-node-node-addon-examples back into node-addon-examples, we've just not had time to do that yet. |
For my needs, I'm confused about the relationship between N-API and... N-API. I don't know exactly how to improve the documentation because I don't actually know the answer to the question. 😛 There's <napi.h> and there's <node_api.h> and it's been simply unclear to me what the relationship is. It looks like the former is "node-addon-api" which is also known as "N-API" whereas the latter is just known as "N-API" and is (for some reason unknown to me, to be honest) compatible with C. I'm just seeing now the following line in the official N-API docs:
I guess I think the vast, vast majority of users are using C++ for addons, so it's unclear to me why node-addon-api is briefly mentioned while the C N-API is covered extensively in the docs. It seems to me the C++ wrapper should be the one covered by default (more-so even than the V8 docs, which take an even higher precedence in the docs) with a footnote saying "by the way, we also have a lower level header called node_api.h if you need C compatibility". I also think one very quick win in this regard would be renaming napi.h -> napi.hpp to make it clear that one is for C++ and one is for C, though I understand this poses other issues (which could be solved by having a napi.h that's just |
I'll think about this suggestion a bit. Officially N-API is the C API and is the API provided by Node.js. node-addon-api is just a convenience for those using C++ similar to nan. I'll have to re-look to see how well covered nan is in the core documentation as a comparison. One thing we should do is to make sure we don't refer to node-addon-api as N-API, but instead as a module supporting the use of N-API. The only way you get napi.h is after having installed node-addon-api, so I'm thinking improving the docs for node-addon-api might be better than renaming napi.h. |
I see. I think maybe the most confusing thing here is the main README of this project. "Node.js API (N-API) Package" is the main title/header and "This package contains header-only C++ wrapper classes for the ABI-stable Node.js API also known as N-API" is extremely ambiguous. I also definitely think covering the distinction much more thoroughly in the main node docs would be very fruitful, as I'd be willing to bet a very small portion of the people on that page would be better served by the N-API than by this wrapper. Maybe I should be bringing that up elsewhere though. I definitely think when the docs here are more thorough, they should have their own page on the official node docs. |
@rivertam once we have completed the docs here , I was going to consider if we might integrate more closely with the core documentation in some way. Do want to get them into a more complete state first. I'll take a look at improving the readme for this project as a first step. |
IMO getting the API docs up to snuff with what's offered for N-API should be the next priority as once that occurs there will be no need to ever reference the N-API docs. |
I would put the usage examples into this repo instead of I discovered with your help pointing me to an open pull request, that you cannot touch the JavaScript objects during Execute(). But I thought maybe I could hold a function and use it in OnOK() since we're back in the main JS thread at that point. But I couldn't get it to work. I strove to understand scopes, and HandleScope, read about it many times but found comprehension impenetrable, both in the I hope this gives some insight into the travails of trying to learn this domain. Thanks! |
@webern I gave a talk related to performance improvements using addons and I fought with the same thing. Here's the repo with the code https://github.com/betomoretti/async-addon. Check the worker files and maybe it will help you :) |
@rivertam @webern we have now revived the node-addon-examples repo and have added an example using |
We should probably remove the outdated Doxygen doc, created this issue for that: #368 |
Going to close this out as there was been a good amount of work completed on the docs, and #368 is there to cover Doxygen. At this point I think we should open a new issue if there is more specific work to do. Going to close, please let us know if this is not the right thing to do. |
I spend a lot of time trying to find things when working with the
napi.h
API.Finding things is quite confusing because there is a website with (outdated?) Doxygen documentation here
https://nodejs.github.io/node-addon-api/napi_8h_source.html
.The main, up-to-date sourcecode seems to be here
https://github.com/nodejs/node-addon-api
.But the usage examples seem to be here
https://github.com/nodejs/abi-stable-node-addon-examples/tree/master/1_hello_world/node-addon-api
.And the name of the project,
node-addon-api
is not very distinguishable from the the built-in node project namedabi-stable-node
which it wraps.The usage examples for
napi.h
code are in the repo namedabi-stable-node-addon-examples
. This name would imply that usage examples should be of theC
N-API
API found underabi-stable-node
, but instead we find usage examples there of thenode-addon-api
.All of this is confusing to a new user of the API. Some explanation up-front in the main readme.md as to the different projects, names, urls, statuses and relationships, as well as either an update or a takedown of
https://nodejs.github.io/node-addon-api/napi_8h_source.html
would be helpful.Ultimately, folding this project into Node.js directly would make a lot of sense to me, and the Node.js documentation itself should say,
here's the ABI stable C API named 'N-API'
andheres the C++ wrapper for 'N-API' named 'N-API-CPP
.Here is a Stack Overflow question I opened, which got tumbleweeds, that illustrates the challenges.
The text was updated successfully, but these errors were encountered: