How it works...
Node.js, as a native runtime environment for JavaScript, provides easy-to-access native libraries that can be built with Rust. In order to do that, the node-ffi (https://github.com/node-ffi/node-ffi) package is required to dynamically find and load the desired libraries. First, however, we start with the Rust code and project: steps 1 to 3 show how to build a native dynamic library, which we discussed earlier in this chapter, in the Including legacy C code recipe, in the How it works... section.
In step 4, we create the JavaScript code. Thanks to the dynamic nature of JavaScript, defining the function signature can be done using strings and objects and the actual invocation looks just like a regular function that can be imported ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access