Node API for .NET: JavaScript + .NET Interoperability
The Node API for .NET project is an innovative solution designed to bridge the gap between the worlds of .NET and JavaScript. This project allows developers to achieve seamless interoperability between these two ecosystems within the same process, enhancing the flexibility and functionality of their applications.
Overview
At the heart of this project is the ability to:
- Load and interact with .NET assemblies directly from a JavaScript application.
- Load and execute JavaScript packages within a .NET application.
Key Features
Node API for .NET is built for high-performance operations and includes several notable features:
- TypeScript Type Definitions: It can generate type definitions, enabling better development experience with TypeScript.
- Async Support: The project supports asynchronous programming both through .NET tasks and JavaScript promises, making it ideal for modern, non-blocking development.
- Stream Interoperability: Developers can easily work with streams across the two environments.
This interoperability leverages the Node API, ensuring compatibility with any Node.js version without the need for recompilation. It's also adaptable to other JavaScript runtimes that support Node API.
Current Status
The project is currently in public preview. While most functionalities perform excellently, there might be some limitations and minor API changes could still occur.
Examples
Node API for .NET provides simple examples to demonstrate its capabilities:
-
JavaScript Invoking .NET:
// JavaScript const Console = require('node-api-dotnet').System.Console; Console.WriteLine('Hello from .NET!'); // JS writes to the .NET console API
-
.NET Invoking JavaScript:
// C# interface IConsole { void Log(string message); } var nodejs = new NodejsPlatform(libnodePath).CreateEnvironment(); nodejs.Run(() => { var console = nodejs.Import<IConsole>("global", "console"); console.Log("Hello from JS!"); // C# writes to the JS console API });
Packages
The project facilitates package management via:
- NPM Package:
node-api-dotnet
for JavaScript environments. - NuGet Package:
Microsoft.JavaScript.NodeApi
for .NET environments.
Development and Contribution
For developers interested in contributing, the project offers comprehensive guides on building, testing, and debugging, located in README-DEV.md
. Contributors are expected to agree to the Contributor License Agreement.
Code of Conduct
The project adheres to the Microsoft Open Source Code of Conduct, promoting a respectful and inclusive community. Any concerns can be addressed via email to [email protected].
Trademarks
This project might include trademarks or logos. Usage must adhere to Microsoft's Trademark & Brand Guidelines, and any third-party trademarks are subject to their respective policies.
Node API for .NET opens up a world of possibilities for developers, allowing them to create dynamic applications with the combined power of .NET and JavaScript.