An open API service indexing awesome lists of open source software.

https://github.com/notnite/nodedotnet

Experimental Node.js native bindings for C# using NativeAOT
https://github.com/notnite/nodedotnet

Last synced: 4 months ago
JSON representation

Experimental Node.js native bindings for C# using NativeAOT

Awesome Lists containing this project

README

          

# NodeDotNet

Experimental Node.js native bindings for C# using NativeAOT. These bindings are extremely incomplete and I'm just doing this for fun!

## Usage

This is only tested on Windows for now.

First, obtain the node-gyp headers & library. I have no idea how to do this automatically, so I just went to `%LocalAppData%\node-gyp\Cache` and copied the latest version I had (naming the folder `node-gyp`).

If the bindings need to be regenerated, use [ClangSharpPInvokeGenerator](https://github.com/dotnet/ClangSharp?tab=readme-ov-file#generating-bindings) with the provided `generate.rsp`.

Then, build a project using NodeDotNet as a library. See `NodeDotNet.Test` for an example, with the right project config and the exposed entrypoint.

## Testing

```shell
# Publish as NativeAOT
dotnet publish -r win-x64
# Rename the file to .node so you can require it
cp ./NodeDotNet.Test/bin/Release/net9.0/win-x64/native/NodeDotNet.Test.dll ./NodeDotNet.Test/bin/Release/net9.0/win-x64/native/NodeDotNet.Test.node
# Run it
node -e 'console.log(require("./NodeDotNet.Test/bin/Release/net9.0/win-x64/native/NodeDotNet.Test.node").add(2, 2))'
```

## TODO

(I probably won't ever finish this)

- [ ] Add more wrapper classes for primitives
- [ ] Better binding to method arguments using Action/Func and generics
- [ ] Bind JavaScript objects to C# classes... somehow...
- [ ] Write a source generator or something for the entrypoint