examples/modules/hello-world/README.md
This example shows the simple napa module, which shows the basic difference between node.js module and napa module.
#include <napa/module.h>
namespace napa {
namespace demo {
using namespace v8;
void Method(const FunctionCallbackInfo<Value>& args) {
auto isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
}
void Init(Local<Object> exports) {
NAPA_SET_METHOD(exports, "hello", Method);
}
NAPA_MODULE(addon, Init)
} // namespace demo
} // namespace napa
It's recommended that typescript or typescript definition is provided to let the user know the APIs without the source codes and develop Typescript project easily.
var addon = require('../bin/addon');
export function hello(): string {
return addon.hello();
}
export declare function hello(): string;
var assert = require('assert');
var helloWorld = require('hello-world');
describe('Test suite for hello-word', function() {
it('prints the string "world"', function() {
var result = helloWorld.hello();
assert.equal(result, 'world');
});
})