NodeJS is based on the v8 JavaScript engine - thus, it is ment to be a standalone app…so embedding it is not a goal you can reach. NodeJS’ core logic relies on being the „one and only“ part of the app - initializing an uv event loop and v8 instance for the process. There is no such way of extending an existing v8 instance with the NodeJS environment (too bad! It’s a shame, really…).
But, there are alternatives:
- Desktop can have nw.js:
http://nwjs.io/
- Mobile could use
https://github.com/paddybyers/anode
There is currently no library or such that maps all NodeJS features into a library, that you can simply use. The main problem I see is that NodeJS requires a uv loop which blocks the currently running thread. To sum up what code NodeJS does
using v8;
// Make the JS context
Isolate* isolate = new Isolate();
context* ctx = new Context(isolate);
// Add NodeJS APIs
node::prepare_environment(ctx);
// Start, run and when no events are left, end the loop.
uv_loop_t *loop = malloc(sizeof(uv_loop_t));
uv_loop_init(loop);
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_close(loop);
free(loop);
The fact that the current thread is blocked may be bad for most applications. Therefore, I can suggest you to actually look into WebViews. These are usually UI classes - different on each platform though… - that allow you to open a website, and in most case, modify the JavaScript environment. I’d suggest you to add common APIs yourself.