4 ms·
Can you use just C for writing node.js addons?
by softinio 11y ago
Can you use just C for writing node.js addons?
- angersock 11y agoUnfortunately not. Node is bound tightly to V8, which is very C++. You can, though, use things like node-ffi.
- anon4 11y agoDoesn't that make the answer "mostly yes, but you need to write the binding in C++"? I.e. write all your code in C, then just call the C methods from the one C++ class you must write.
- angersock 11y agoEh, by that logic, we can write Node extensions in Fortran or Brainfuck.
- nawitus 11y agoYou can write the library/addon in C and then define the bindings with JavaScript using various npm libraries. There's no need for C++. Here's an example of such a wrapper over a C library: https://github.com/panuhorsmalahti/mtp https://github.com/panuhorsmalahti/mtp
- indutny 11y agoI think it might be possible to do it with some sort of wrapping library written in C++ with C APIs. Technically, it will work this way for every kind of C++ library.
- SCHiM 11y agoIf you want to go a little overboard it's possible to use the C abi and write a thin wrapper in C++.