Create node.js addon CLI
https://github.com/himself65/create-addon.git
๐ Create Node.js native addons with ease
A modern CLI tool for scaffolding Node.js native addon projects with an interactive interface. Generate boilerplate code for C++, Objective-C, and Swift addons with platform-specific templates.
node-addon-api for modern native bindingsnpm install -g create-addon
Or use directly with npx:
npx create-addon my-project
Launch the interactive CLI to create a new project:
create-addon
Provide a project name and select a template interactively:
create-addon my-awesome-addon
Create a project with all options specified:
create-addon my-awesome-addon --template cpp-linux
C++ addon optimized for Linux platforms with GTK+ integration.
Features:
C++ addon designed for Windows platforms.
Features:
Objective-C addon for macOS with native Cocoa integration.
Features:
Swift addon for macOS with modern Swift integration.
Features:
# Create a C++ addon for Linux
create-addon my-cpp-addon --template cpp-linux
# Create a Swift addon for macOS
create-addon my-swift-addon --template swift
# Create an Objective-C addon
create-addon my-objc-addon --template objective-c
# Create a Windows C++ addon
create-addon my-win-addon --template cpp-win32
create-addon my-project --skip-install
create-addon [project-name] [options]
Options:
-t, --template <template> Template to use (cpp-linux, cpp-win32, objective-c, swift)
--skip-install Skip installing dependencies
-h, --help Show help
Each generated project includes:
my-project/
โโโ binding.gyp # node-gyp build configuration
โโโ package.json # Project configuration and scripts
โโโ src/ # Native source code
โ โโโ addon.cc # Main addon implementation
โ โโโ ... # Additional source files
โโโ include/ # Header files
โ โโโ *.h # Platform-specific headers
โโโ js/
โโโ index.js # JavaScript wrapper with EventEmitter
After creating your project:
cd my-project
# Install dependencies
npm install
# Build the native addon
npm run build
# Clean build artifacts
npm run clean
# Build for Electron (if needed)
npm run build-electron
Generated addons follow a consistent EventEmitter pattern:
const addon = require("./js/index.js");
// Basic usage
console.log(addon.helloWorld("Hello from Node.js!"));
// GUI interaction (platform-specific)
addon.helloGui();
// Event handling
addon.on("todoAdded", (todo) => {
console.log("New todo:", todo);
});
addon.on("todoUpdated", (todo) => {
console.log("Updated todo:", todo);
});
addon.on("todoDeleted", (todo) => {
console.log("Deleted todo:", todo);
});
# Clone the repository
git clone https://github.com/himself65/create-addon.git
cd create-addon
# Install dependencies
pnpm install
# Build the CLI
pnpm run build
# Test locally
node dist/bin.js
# Build with watch mode
pnpm run dev
We welcome contributions! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)pnpm run build)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)MIT ยฉ himself65
Credits to the Felix electron-native-code-demos for inspiration and initial templates.