Embedded node, call c++ -> js

880 views
Skip to first unread message

Al Izi

unread,
Jul 3, 2018, 11:15:46 AM7/3/18
to nodejs
Let's say there is embedded node engine inside a C++ application. What is the right way to call a js function from native code? I don't see any exposed v8 interfaces (for instance v8::Isolate). Also how to start node in this case? node::Start(argc, argv) starts node command loop and most probably I even don't need one.

sbusch

unread,
Jul 4, 2018, 12:08:20 PM7/4/18
to nodejs
Hi,

you might be interested to have a look at this fork of node.js:

This was a student project last year, where the students created a library interface for node.js for exactly that purpose. In short, you have much more control over how you embed node.js into your C++ application, e.g., you can initialize node and just run a script, without invoking the main loop at all, invoke the main loop later, or just call a function from a node.js module from your C++ code. In general, you have fine-grained control over the embedding and do not need to work with the node::Start() function.

Usage examples can also be found here:

There was also a pull request for this, which has been closed: https://github.com/nodejs/node/pull/19005

I still think it would be a great step forward for node.js, if the embedding interface would be improved to make it easier to integrate node.js into C++-applications, and this questions pretty much exemplifies this. There are more projects out there now, which embed node.js into their applications, and right now the interface for that is pretty hard to use, making it necessary to "hack your way around". The student project tried to improve on that situation, and I think they have done a terrific job (disclaimer: I was the supervisor for their project).

So maybe we could have another look at their proposal or at least at the general idea of improving the interface for embedders?

Stefan

Vicente Eduardo

unread,
Jan 9, 2019, 10:48:04 AM1/9/19
to nodejs
I have published recently MetaCall, which is a library that allows you to call functions between languages. NodeJS is one backend supported by it so you will be able to embed NodeJS into your C++ application without dealing with NodeJS internals. I leave here the link to the repository:

Reply all
Reply to author
Forward
0 new messages