I am no C++ expert, in fact I’m quite a noobie, but I have read a lot of it (it is used to ilustrate programming concepts in sooooo many books) and even managed to write a couple of command line tools for my own use. Anyway, the idea in this post is to show the most basic interaction between a C++ module and node.js. The examples I have seen have been very useful, but I felt the need to simplify the code even more and reduce the “hello world” module into the bare minimum.
So this is my go at it (this has been updated to work with Node.js v4.0.0):
This code registers a module called
cpphello. This module has one method called
foo, and this method simply returns a string (“Hello World”).
UPDATE: This example has been updated thanks to pull requests from kul
foo run in 167ms cppfoo run in 18ms c++ was 9.3 times faster