C
C#2w ago
wasabi

Invoking NodeJS from C#

I happen to have a need for this. From my research it doesn't appear that NodeJS distributes a library by default. I can't find any recent and maintained PInvoke bindings for anything. So, asking here before I start to build something. I think the idea would be to rebuild node myself as a shared or static library, and then link it into some bridge C/C++ code, and then P/Invoke against that. But checking if somebody is aware of a better way to go about it.
9 Replies
sibber
sibber2w ago
ipc is an option maybe grpc or a named pipe maybe
wasabi
wasabiOP2w ago
I should alter the topic. I am specifically interested in inprocess scenarios.
Shazanman
Shazanman2w ago
there's the IJSRuntime if you want to call JS function from .net would be helpful if you can elaborate your exact use case?
wasabi
wasabiOP2w ago
I mean I don't know how I can be any more specific than pinvoking into nodejs. Anyways. My research has found a node has has a build option to produce the runtime into a libnode. Which unfortunately has a really crap C++ API surface. But which can then be wrapped in a flat C API for pinvoke.
wasabi
wasabiOP2w ago
And I found this project which is attempting to do the same: https://github.com/microsoft/node-api-dotnet Though it's pretty early, and I don't know what the progress is.
GitHub
GitHub - microsoft/node-api-dotnet: Advanced interoperability betwe...
Advanced interoperability between .NET and JavaScript in the same process. - microsoft/node-api-dotnet
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
wasabi
wasabiOP2w ago
GitHub
GitHub - alethic/Microsoft.JavaScript.LibNode: Native Node library ...
Native Node library packages. Contribute to alethic/Microsoft.JavaScript.LibNode development by creating an account on GitHub.
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
wasabi
wasabiOP2w ago
Yeah. Nobody ever used it.

Did you find this page helpful?