Embedding node inside Rust

Is there anyway to embed node inside Rust (not neon, which embeds Rust modules in Node).

Googling around, I found:

Embedding Node.js in Rust?


so it appears to be something of interest but no clear solution.

[My main goal is to be able to use Node.js libraries from Rust]

You might be able to use Deno Core:

Or if that is too Deno-y and you just want to embed V8:

Which is the JS bindings used by Deno.

Oops, I just read "[My main goal is to be able to use Node.js libraries from Rust]". That probably won't work, then :man_facepalming: :confused: . I don't think that Deno is compatible with node modules.

Node.js itself isn't designed to be embeddable, AFAIK. It assumes it exists in a specified location on disk, where it can put global node_modules and include dirs for gyp-based modules.

Even if you embed node executable into your Rust executable, you will still need to have the rest of node's installation on disk.

You may as well just bundle the whole Node tarball with your project. Just launch node executable from disk. You'll get process isolation as a bonus :slight_smile:

1 Like