3 ms·
On a related note, if you've mostly spent time with JavaScript, and you've always wanted to write a fast native binding for Node.js but didn't know any C, or if
by jorangreef 5y ago
On a related note, if you've mostly spent time with JavaScript, and you've always wanted to write a fast native binding for Node.js but didn't know any C, or if you ever had issues with the node-gyp build system, then you can even use Zig to write and compile native bindings for Node.js, without a line of C, and without any node-gyp:
zig build-lib -dynamic -lc -isystem /usr/include/node example.zig -femit-bin=example.node
Here's an example repo with everything you need to give it a shot!
https://github.com/ifreund/zig-napi-example https://github.com/ifreund/zig-napi-example
This uses Node's N-API, which is actually a C header, but which is consumed perfectly from within Zig. And here are the relevant N-API docs: https://nodejs.org/api/n-api.html https://nodejs.org/api/n-api.html