Thursday | 21 NOV 2024
[ previous ]
[ next ]

How to start a node addon project

Title:
Date: 2022-03-22
Tags:  

This is just a quick post to write down how to start a node addon project.

We first install the generator.

> npm install -g yo generator-napi-module

Next we start our project and we're going to choose the object wrap template.

> mkdir d3
> cd d3
> yo napi-module
...
    ? Choose a template Object Wrap
    ? Would you like to generate TypeScript wrappers for your module? No
...

Now that we have our template project, we can build it and make sure it works.

> node-gyp configure build
> npm test

At this point we should have a working base. I delete the test file and the bindings.js in lib as I'm going to fudge things a little bit. I'm sure there's a good reason for the way things are but I find that I'd rather have it make sense to me and be natural to use. Lib to me means it contains library files and I'll be setting up and index.js file later that maps all the C functions to javascript anyway.

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