Node.js Native Addon Example
This project is a minimal example of a Node.js native addon written in C++ and built with node-gyp, exposing a simple function to JavaScript.
Overview
The addon compiles a C++ binding into a native .node module that can be required from Node.js and invoked like a normal JavaScript function.
Project Structure
-
src/binding.ccMain C++ source file defining the native addon. -
binding.gypnode-gypbuild configuration. -
build/Generated build artifacts (created bynode-gyp). -
test.js/test-worker.jsSimple test scripts to verify the addon. -
package.jsonProject metadata and dependencies.
Prerequisites
-
Node.js (with headers available)
-
Python (required by
node-gyp) -
C/C++ build tools
- Linux:
build-essential - macOS: Xcode Command Line Tools
- Windows: Visual Studio Build Tools
- Linux:
Build Instructions
Run the following commands in the project root:
node-gyp configure
node-gyp build
This will generate the native module under build/Release/.
Usage
Example JavaScript usage:
const binding = require("./build/Release/binding");
console.log(binding.hello()); // outputs: "hello world"
Notes
- This repository is intended as a learning or reference project.
- The build output should not be edited manually.
- For distribution, consider ignoring
build/in version control and rebuilding per environment.
License
MIT