I want to create my own native Nodejs module. I have been following http://nodejs.org/docs/latest/api/addons.html and try to understand how to create native module .
First created hello.cc
#include <node.h>
#include <v8.h>
using namespace v8;
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("world"));
}
void init(Handle<Object> exports) {
exports->Set(String::NewSymbol("hello"),
FunctionTemplate::New(Method)->GetFunction());
}
NODE_MODULE(hello, init)
Then created binding.gyp
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ]
}
]
}
Then I ran these command
node-gyp configure
node-gyp build
finally created hello.js
var addon = require('./build/Release/hello');
console.log(addon.hello());
At this time I got error like
module.js:355
Module._extensions[extension](this, filename);
and so on.
I tried to build your example but I don't achieve to complete because of V8 versions.
So I followed the nodejs addon example again. Today the example is a little different at yours. And all works right.
My environment is the following:
I hope this will be useful.