A boilerplate for creating a C++ npm package
Did you like the project? Please, considerate a donation to help improve!
A boilerplate for creating a C++ npm package✨
Install with yarn or npm:
yarn
ornpm
:
# yarn
yarn add cpp-npm-package-boilerplate
# npm
npm i cpp-npm-package-boilerplate --save
import { helloNative } from 'cpp-npm-package-boilerplate';
console.log(helloNative('C++')); // Hello C++
Note: This is example is a binding of the C++ function
helloNative
to the JavaScript functionhelloNative
.
#include <napi.h>
Napi::String Method(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
return Napi::String::New(env, "world");
}
Napi::Object Init(Napi::Env env, Napi::Object exports)
{
exports.Set(Napi::String::New(env, "hello"),
Napi::Function::New(env, Method));
return exports;
}
NODE_API_MODULE(hello, Init)
import bindings from 'bindings';
export const helloNative = bindings('hello.node').hello;
import bindings from 'bindings';
type THelloNative = (string: string) => string;
export const helloNative: THelloNative = bindings('hello.node').hello;
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Or buy me a coffee 🙌🏾
Copyright © 2023 Hebert F Barros.
This project is MIT licensed.