Edge.js allows you to run .NET and node.js code in one process. You can call .NET functions from node.js and node.js functions from .NET. Edge.js takes care of marshaling data between CLR and V8. Edge.js also reconciles threading models of single threaded V8 and multi-threaded CLR. Edge.js ensures correct lifetime of objects on V8 and CLR heaps. The CLR code can be pre-compiled or specified as C# or Python source: edge.js can execute C# or IronPython script at runtime. Edge allows CLR languages other than C# or IronPython to be plugged in.
More information here: https://github.com/tjanczuk/edge.
To get started:
- Download and install node.js from the node.js website(http://nodejs.org/download/)
- Start a command prompt
- Browse to the location where you want to run node
- Install edge through the npm package manager:
npm install edge
- Create a hellocsharp.js file in the current folder and add the following code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var edge = require('edge'); | |
var helloWorld = edge.func('async (input) => { return ".NET Welcomes " + input.ToString(); }'); | |
helloWorld('JavaScript', function (error, result) { | |
if (error) throw error; | |
console.log(result); | |
}); | |
- Run the program: node hellocsharp.js