-
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathhello.cc
More file actions
23 lines (18 loc) · 756 Bytes
/
hello.cc
File metadata and controls
23 lines (18 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <napi.h>
static Napi::String Method(const Napi::CallbackInfo& info) {
// Napi::Env is the opaque data structure containing the environment in which
// the request is being run. We will need this env when we want to create any
// new objects inside of the node.js environment
Napi::Env env = info.Env();
// Create a C++ level variable
std::string helloWorld = "Hello, world!";
// Return a new javascript string that we copy-construct inside of the node.js
// environment
return Napi::String::New(env, helloWorld);
}
static 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)