read

The latest release of the Edge.js project adds support for scripting Node.js from a .NET application. This enables you to leverage the power of Node.js ecosystem with the thousands of NPM modules from within a CLR application.

Learn more
Get the all-inclusive Edge.js NuGet package

You can now script Node.js code (not just JavaScript) within a .NET or ASP.NET web application written in C# or any other CLR language:

DoubleEdge

The Edge.js project existed for a while, but until now it only allowed scripting CLR code from a Node.js process on Windows, MacOS, and Linux. With the latest release, you can also script Node.js code from a CLR process.

You can call .NET functions from Node.js and Node.js functions from .NET. Edge.js takes care of marshalling data between CLR and V8. Edge.js also reconciles threading models of single threaded V8 and multi-threaded CLR, and ensures correct lifetime of objects on V8 and CLR heaps.

The most powerful aspect of the Node.js scripting capability that Edge.js just enabled is that you can tap onto the many thousands of Node.js modules available both in the Node.js runtime as well as on NPM. For example, you can now create a websocket server in Node.js with a message handler in C#, all running within a single CLR process.

Getting started

Open Visual Studio 2013 and create a new .NET console application. Then add the Edge.js NuGet package to the project using the NuGet Package Manager:

image

Now add a using directive for Edge.js:

1
using EdgeJs;

And implement the body of the Main method:

1
2
3
4
5
6
7
8
9
10
static void Main(string[] args)
{
    var func = Edge.Func(@"
        return function(data, cb) {
            cb(null, 'Node.js ' + process.version + ' welcomes ' + data);
        };
    ");

    Console.WriteLine(func(".NET").Result);
}

Compile, run, and enjoy!

image

Learn more

Here are more resources to get your started using Edge.js:

Overview

Get the all-inclusive Edge.js NuGet package
Scripting Node.js from CLR
What you need
Hello, world
Using built-in Node.js modules
Using NPM modules
Handle Node.js events in C#
Manage Node.js state from C#
Script Node.js in ASP.NET

Blog Logo

Tomasz Janczuk


Published

Image

Tomek on Software

Software - shaken, not stirred

Back to Overview