Skip to main content

napi 0.23.0 copy "napi: ^0.23.0" to clipboard
napi: ^0.23.0 copied to clipboard

Generate Dart bindings for Node-API addons and WebAssembly modules.

example/README.md

Dart Counter #

Build a JavaScript package from Dart with napi. Use Dart 3.13.5 and Node.js 24.19.0 or 26.11.1.

From this directory:

dart pub get
dart run tool/build.dart
npm install ./npm-package
node example.mjs

The example prints 1 and 3. Edit lib/counter.dart to change the Dart API. @NAPI() exports the class, including its constructor, fields and methods.

The build declaration in tool/build.dart sets the npm package name, version, output directory and backend. Change name and the import in example.mjs for your own package. The Dart project name in pubspec.yaml is independent of the npm name.

For a native Node-API addon, set target: BuildTarget.native, or select it for one build:

dart run tool/build.dart --target native

Native builds download a matching runtime on first use; see supported platforms. Wasm builds do not download a native runtime.

The build script can have any name. It is ordinary Dart code; use package.build() when calling it programmatically, or package.run(args) to expose its command-line options. Run it from the project directory so relative paths resolve to this project.

To install the package elsewhere, create an npm tarball:

npm pack ./npm-package

Install that tarball in the consuming Node project. The package initializes when imported and includes TypeScript declarations.

2
likes
0
points
1.04k
downloads

Publisher

verified publishermedz.dev

Weekly Downloads

Generate Dart bindings for Node-API addons and WebAssembly modules.

Repository (GitHub)
View/report issues

Topics

#wasm #node #interop

License

unknown (license)

Dependencies

analyzer, args, crypto, package_config, path

More

Packages that depend on napi