Edge.js is an innovative (and curious) library that allows you to run .NET code from Node.js and vice versa, facilitating integration between these two popular technologies.
Edge.js combines the best of both worlds, allowing developers to use .NET libraries and components in Node.js applications and vice versa.
This integration, aside from being a monstrosity and an abomination of nature 😅, is useful in scenarios where applications require features from one of the languages that are not readily available in the other.
Main features,
- Interoperability: Run .NET code from Node.js and Node.js code from .NET.
- Compatibility: Supports .NET Core and .NET Framework.
- Ease of Use: Simple and easy-to-use API for integrating both technologies.
- Performance: Leverages the native performance of .NET and the efficiency of Node.js.
For more information and details on how to use Edge.js, visit the GitHub repository. Here you will find additional documentation, usage examples, and updates on this tool.
Installation
Installing Edge.js in Node.js
Install Edge.js using npm:
npm install edge-js
Installing Edge.Js in .NET
Install Edge.js using nuget:
Install-Package EdgeJs
Using Edge.js
Running C# Code from Node.js
One of the main features of Edge.js is the ability to run C# code from Node.js. Below is an example of how to achieve this.
Create a file app.js
with the following content:
const edge = require('edge-js');
const helloWorld = edge.func(function () {/*
async (input) => {
return ".NET welcomes " + input.ToString();
}
*/});
helloWorld('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
Run the script from the command line:
node app.js
You should see the output: .NET welcomes Node.js
Running Node.js Code from .NET
Edge.js also allows you to run Node.js code from a .NET application. Here is an example of how to do it:
Create a new .NET project and add Edge.js as a dependency:
dotnet new console -n EdgeJsExample
cd EdgeJsExample
Write .NET Code to Run Node.js
using System;
using System.Threading.Tasks;
using EdgeJs;
class Program
{
public static async Task Start()
{
var func = Edge.Func(@"
return function (data, callback) {
callback(null, 'Node.js welcomes ' + data);
}
");
Console.WriteLine(await func(".NET"));
}
static void Main(string[] args)
{
Start().Wait();
}
}
Run the .NET project from the command line:
dotnet run