Tuesday, March 12, 2013

Run C# and node.js code in-process with no compilation

The edge.js project allows running .NET and node.js code in-process. With the edge@0.7.0 release,  you can now embed C# code in directly in the node.js application, without the hassle of projects, compilation, and DLLs. Edge.js will compile the C# code automatically in-memory before running it.

Note: the edge.js project was previously called “owin”. If you know it by that name, this explains why it was renamed.

image

Edge.js provides a prescriptive, asynchronous model for calling .NET code from node.js and node.js code from .NET. Edge.js module takes care of marshaling data between V8 and CLR and reconciling the threading models. And with edge@0.7.0 you no longer have to deal with C# compilation and CLR DLLs as edge.js compiles C# sources for you on the fly.

Everything you need to get started is covered at http://tjanczuk.github.com/edge. Poll requests and feedback are welcome.

For specific topics check out previous posts:

Run node.js and .NET code in-process
Access MS SQL from node.js using OWIN
Implement CPU-bound computations on CLR threads within node.js process
Hosting .NET code in node.js process using OWIN

8 comments:

  1. This project sounds very cool. Does it also work with other .NET languages such as F#? Thanks

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This supports any CLR language that allows you to create an instance of Func<object,Task<object>> and compile it down to a managed DLL. The on-the-fly source code compilation introduced in 0.6.0 works only with C#.

      Delete
  2. This is a magical project.

    ReplyDelete
  3. Is there a chance that you're working towards a method of hosting node.js inproc in a .NET process? (I'd seriously enjoy that too.)

    I have a dynamic powershell class for c# that asynchronously exposes powershell cmdlets trivially to c#. I think with this sort of thing, we could expose the cmdlets to node too... (aw, that's so very cool).

    ReplyDelete
    Replies
    1. Hosting node.js in a .NET process is on the roadmap: https://github.com/tjanczuk/edge/issues/17. You may also be insterested in Doug Finke's PowerShell compiler for edge.js at https://github.com/dfinke/edge-ps.

      Delete
  4. Nice work Thomasz - thank you. Two questions:

    I'm trying to find a way to call Esentutl (Extensible Storage Engine) functions directly from node.js. Is there anyway to accomplish this directly? I'm a minimalist, and would rather avoid using .Net (with ManagedEsent) in this particular context. Can you point me in the right direction in terms of linking node.js with Esentutl.exe?

    Thanks!

    ReplyDelete
  5. Upon reading your post entitled "CPU bound workers for node.js applications using in-process .NET and OWIN", it seems perhaps Edge would be a possible solution, after all.

    We're rewriting our Silverlight based software (www.acuproject.com) in HTML5, and in the interest of performance are leaning towards ESE (Extensible Storage Engine) as our database. We also have real time scheduling logic written in C# that we intended to port to javascript for use in node.js (V8).

    Edge perhaps presents an alternative solution, but what about latency/delays in calling C# from javascript? In our case, we would frequently call from javascript the C# rescheduling & database logic and receive a returned array. Do you have an estimate as to the delay in communicating with .Net from the node.js process?

    Regards,
    Phil



    ReplyDelete

My Photo
My name is Tomasz Janczuk. I am currently working on my own venture - Mobile Chapters (http://mobilechapters.com). Formerly at Microsoft (12 years), focusing on node.js, JavaScript, Windows Azure, and .NET Framework.