Skip to content

Instantly share code, notes, and snippets.

@tcr
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcr/b99edad665936b46f20a to your computer and use it in GitHub Desktop.
Save tcr/b99edad665936b46f20a to your computer and use it in GitHub Desktop.
Hello World for Node
node_modules
out
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ],
"include_dirs": [
"<!(node -e \"require('nan')\")"
]
}
]
}
#include <nan.h>
using namespace v8;
NAN_METHOD(Method) {
NanScope();
NanReturnValue(NanNew("Hello world!"));
}
void Init(Handle<Object> exports) {
exports->Set(NanNew("hello"), NanNew<FunctionTemplate>(Method)->GetFunction());
}
NODE_MODULE(hello, Init)
var addon = require('bindings')('hello');
console.log(addon.hello()); // 'world'
{
"name": "hello_world",
"version": "0.0.0",
"description": "Node.js Addons Example #1",
"main": "hello.js",
"private": true,
"dependencies": {
"bindings": "^1.2.1",
"mkdirp": "^0.5.1",
"nan": "^1.8.4"
},
"scripts": {
"test": "node hello.js"
},
"gypfile": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment