node-addon-examples icon indicating copy to clipboard operation
node-addon-examples copied to clipboard

is NAN still the name of the game

Open ORESoftware opened this issue 6 years ago • 9 comments

Is NAN still the state of the art way to create Node.js addons? Looking at a repo like this:

https://github.com/nodejs/node-addon-examples/tree/master/1_hello_world

it looks like NAPI has overtaken NAN, or?

this info should go in the readme, telling users which one is the most recent version to use?

ORESoftware avatar Jan 05 '19 04:01 ORESoftware

see: https://github.com/nodejs/node-addon-examples/pull/75

ORESoftware avatar Jan 05 '19 04:01 ORESoftware

wrt to the hello_world example - it's unclear what the difference is between napi and node-addon-api, two different directories, if you follow.

ORESoftware avatar Jan 05 '19 04:01 ORESoftware

I was originally trying to make an addon using NAN since it had been around longer and there were more tutorials available. Then I came across the node-addon-api and found it much easier to get started. This is coming from somebody that does not know c++.

If you want to see a more complicated addon using node-addon-api made by somebody that is just piecing it together and somehow made it work, then check it out here. It is still a work in progress. Just converted it to use async_workers. Next, I will try to incorporate object_wrap so that I can store configuration data.

kevinGodell avatar Jan 05 '19 16:01 kevinGodell

We probably need some more doc if the difference between napi and node-addon-api is not clear. napi uses the core C API provided by Node.js, while node-addon-api uses the C++ wrapper -> https://github.com/nodejs/node-addon-api

mhdawson avatar Jan 07 '19 15:01 mhdawson

@mhdawson yeah that would be a good addition to readme imo

ORESoftware avatar Jan 08 '19 00:01 ORESoftware

I created a PR to briefly document the API implementation differences, with links to their own docs. I also reordered the page, as I think it flows better to know what's in the repo first before seeing how to use it.

Secondly, I do not think we should include a recommendation within the readme of which implementation to go for. Each has their own pros and cons, and it really depends on your use case. This is an interesting blog post that goes pretty in-depth about the history of each.

Thoughts?

KevinEady avatar Jan 26 '19 02:01 KevinEady

I think https://github.com/nodejs/node-addon-examples/pull/156 will address this. It echo's what is in the N-API documentation.

mhdawson avatar Sep 22 '20 18:09 mhdawson

Sorry, I still don't understand if node-addon-api is a replacement for NAN or not? when should you use either?

rprovodenko avatar Oct 25 '20 15:10 rprovodenko

@rostislavdeepcrawl the doc says use N-API unless it does not cover functionality that you need. N-API does not expose 100% of the V8 API surface so you can't use it in all cases. If it covers what you need you should use N-API.

mhdawson avatar Oct 26 '20 18:10 mhdawson