:: krowemoh

Sunday | 29 DEC 2024
Posts Links Other About Now

previous
next

Node Addon API

2022-02-05

Writing a C addon for Node is pretty straightforward. The build process was a hassle to set up but outside of that, there are plenty of examples to look at thought not much in the way of tutorials.

https://nodejs.github.io/node-addon-examples/getting-started/first/

Luckily the examples cover a lot of the use cases and if you start small then it should be doable to learn as you go.

https://github.com/nodejs/node-addon-examples

One thing I learned a bit late was that there are C examples and C++ examples, it would have probably been easier to use C, as the intercall library I was using was a C library but the C++ style did work.

It would be helpful to have had an idea of node-gyp does as from what I can tell its a node wrapper around python scripts that are replacements for makefiles. Maybe? I'll need to read up a bit more on what gyp is. I do wish I just had a single makefile that the bare command I need to run just for learning.

Working with the node-addon-api is pretty easy, passing variables through javascript was simple but I also kept the project very simple as I only passed around arrays and strings. I also tried writing a C level library for python before and remember it being very cumbersome and gave up near the beginning. This was a nice experience where the project finished and works well enough.