How to compile node.js with additional addon?

72 views
Skip to first unread message

Hai Phan

unread,
Aug 3, 2015, 10:30:53 AM8/3/15
to nodejs

I'm relatively new to node.js and I have a question about compiling node.js with additional native module. Is there a way to integrate an addon to node.js so that it is ready for use after compile?


node.js source code is here. Some built-in libraries are located in deps/


There is a tutorial for compiling C++ addon as a module of node.js. After compilation of the module a file "myaddon.node" is generated that can be used with require in node.js application.


Is there a way to make the module built-in? I mean I can just compile it together with node.js source code and then deploy to a target machine. So that I can just call


var myaddon = require("myaddon");


without having to run npm install. There are natives modules such as zlib, http, fs that are integrated into node.js.


I found one article where a native module is built for node.js on Windows using Visual Studio. Is there a similar way to build node.js with your own module on Linux?

Roman Khmelichek

unread,
Aug 5, 2015, 5:17:41 PM8/5/15
to nodejs
You can take a look at nad (Node Addon Development): https://github.com/thlorenz/nad

What it does is take your addon's binding.gyp file and injects it into node's node.gyp file.
So, when you compile node.js, your addon will be compiled in as well.
This allows your addon to function just like the built in modules like zlib, etc.
nad is somewhat OS X focused because it'll open the project in XCode - but you can just as easily produce a Makefile for Linux.

`nad inject` will inject the binding.gyp of the addon into node's node.gyp

Then, you can build node.js as usual, e.g.:
$ ./configure
$ make

Your addon will be compiled into the node binary.
Reply all
Reply to author
Forward
0 new messages