Last active
August 29, 2015 14:22
-
-
Save tcr/b99edad665936b46f20a to your computer and use it in GitHub Desktop.
Hello World for Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
out | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"targets": [ | |
{ | |
"target_name": "hello", | |
"sources": [ "hello.cc" ], | |
"include_dirs": [ | |
"<!(node -e \"require('nan')\")" | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addon = require('bindings')('hello'); | |
console.log(addon.hello()); // 'world' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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