Script Node.js from .NET using Edge.js

Hero Image

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:

using EdgeJs;

And implement the body of the Main method:

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


ArrowPrevious
NextArrow

Most Recent

24 January 2022
Run Node.js from Google Sheets

Import data from any API or data source to Google Sheets using Node.js, NPM, and Fusebit Connectors.

21 January 2022
Linear and Discord Slash Commands

Learn how to build an interactive Slash Command for a Discord bot that lets users create a new issue in Linear.

19 January 2022
Add Slash Commands to Your Discord Bot!

Slash Commands are an extremely powerful way to provide rich interactivity for members of your Discord server, all you have to do is type “/” and you're ready to use your favorite bot.