2014-05-31

Embedding Node.js in your .NET F# App

Edge.js now allows you to embed Node.js in your .NET app! You can call .NET functions from the JavaScript code by passing in async functions with a particular signature. Here is a small F# app that calls a JavaScript function to append the Node.js version to the string passed in. The JavaScript function calls a .NET function to append the .NET version. It prints "This has Node.js v0.10.28 embedded in a .NET 4.0.30319.34014 app written in F#."


Show me the code.
Loading gist for edgejs2.fs ...
I did write a couple of static extension methods for Edge and Async to make it easier to pass in and return async F# functions. It adapted the required signature that Edge.js uses for interop.
Loading gist for EdgeJs.FSharp.fs ...
When you install the NuGet package, prebuilt dll's for Node.js come with it.


I thought this would be more interesting than the basic hello world in F#. Edge.js opens up the door to embedding Node.js in F# apps and this could lead to some very cool integrations.