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
ipc is an option
maybe grpc
or a named pipe maybe
I should alter the topic. I am specifically interested in inprocess scenarios.
there's the IJSRuntime if you want to call JS function from .net
would be helpful if you can elaborate your exact use case?
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.
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•2w ago
Message Not Public
Sign In & Join Server To View
Ended up building my own. https://github.com/alethic/Microsoft.JavaScript.LibNode/
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•2w ago
Message Not Public
Sign In & Join Server To View
Yeah. Nobody ever used it.