Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access .so library from nodejs application

Tags:

c

node.js

.so

I have a piece of C code which returns a string output. The same api is packaged in the form of a .so file.

How can i use the .so file directly in my nodejs code. Do i need to add something in my C code or there is a standard mechanism in node for the same..?

Thanks

like image 887
asharma Avatar asked Dec 05 '25 09:12

asharma


1 Answers

You can't. What you can do is to write a C executable which uses the so library and returns an output. You can call this in your js file using the exec function.

exec('/<path_to_executable>/executable',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});
like image 158
Ricketyship Avatar answered Dec 07 '25 03:12

Ricketyship



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!