Hacker News new | ask | show | jobs
by electroly 2838 days ago
Native code has two benefits over JavaScript: it's faster, and it can call the OS. WASM is faster, but it can't call the OS. It cannot replace all uses of native modules.
2 comments

Calling the OS doesn't require native modules, it should be supported via a native cffi in node, like in Python.
Are you describing something you wish that node had, or something that actually exists? As far as I'm aware, native modules are the FFI for node, and that every package that involves presenting an FFI to the developer is using a native module to do it.
Node doesn't have it natively like Python does, but it exists:

https://github.com/node-ffi/node-ffi

Yeah, that's a native module. If you look at the C source code in "src", the "NAN_METHOD" and stuff are Node native module macros. node-ffi will not work if they remove native modules.
Wasm on the browser can't call the OS, but I don't assume that to be the case on Node, just like it isn't for JS.
JS (and eventually wasm) calls the OS via requiring native modules, which is why we're concerned about keeping them around.