SkillAgentSearch skills...

Edge

Run .NET and Node.js code in-process on Windows, MacOS, and Linux

Install / Use

/learn @tjanczuk/Edge
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Edge.js: .NET and Node.js in-process Build Status

Up to date project can be found here https://github.com/agracio/edge-js

NPM package is published as edge-js

Nuget package is published as EdgeJs

Any Issues or PRs should be created in https://github.com/agracio/edge-js


NEW Edge.js is now on Slack at https://edgejs.slack.com. Join here.

An edge connects two nodes. This edge connects Node.js and .NET. V8 and CLR/.NET Core/Mono - in process. On Windows, MacOS, and Linux.

image

You can script C# from a Node.js process:

ES5

var edge = require('edge');

var helloWorld = edge.func(function () {/*
    async (input) => { 
        return ".NET Welcomes " + input.ToString(); 
    }
*/});

helloWorld('JavaScript', function (error, result) {
    if (error) throw error;
    console.log(result);
});

ES6

In ES6 you can use template strings to write multiline C# code.

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);
});

You can also script Node.js from C#:

using System;
using System.Threading.Tasks;
using EdgeJs;

class Program
{
    public static async Task Start()
    {
        var func = Edge.Func(@"
            return function (data, callback) {
                callback(null, 'Node.js welcomes ' + data);
            }
        ");

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

    static void Main(string[] args)
    {
        Start().Wait();
    }
}

What problems does Edge.js solve?

Ah, whatever problem you have. If you have this problem, this solves it.

--Scott Hanselman (@shanselman)

Before you dive in

See the Edge.js overview.
Read the Edge.js introduction on InfoQ.
Listen to the Edge.js podcast on Herdingcode.

image

Contents

Introduction
Scripting CLR from Node.js
    What you need
        Windows
        Linux
        OSX
        Docker
    How to: C# hello, world
    How to: integrate C# code into Node.js code
    How to: specify additional CLR assembly references in C# code
    How to: marshal data between C# and Node.js
    How to: call Node.js from C#
    How to: export C# function to Node.js
    How to: script Python in a Node.js application
    How to: script PowerShell in a Node.js application
    How to: script F# in a Node.js application
    How to: script Lisp in a Node.js application
    How to: script T-SQL in a Node.js application
    How to: support for other CLR languages
    How to: exceptions
    How to: app.config
    How to: debugging
    Performance
    Building on Windows
    Building on OSX
    Building on Linux
    Running tests
Scripting Node.js from CLR
    What you need
    How to: Node.js hello, world
    How to: integrate Node.js into CLR code
    How to: use Node.js built-in modules
    How to: use external Node.js modules
    How to: handle Node.js events in .NET
    How to: expose Node.js state to .NET
    How to: use Node.js in ASP.NET application
    How to: debug Node.js code running in a CLR application
    Building Edge.js NuGet package
    Running tests of scripting Node.js in C#
Use cases and other resources
Contribution and derived work

Introduction

Edge.js allows you to run Node.js and .NET code in one process on Windows, MacOS, and Linux.

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. Edge.js ensures correct lifetime of objects on V8 and CLR heaps. The CLR code can be pre-compiled or specified as C#, F#, Python, or PowerShell source: Edge.js can compile CLR scripts at runtime. Edge can be extended to support other CLR languages or DSLs.

Edge.js interop model

Edge.js provides an asynchronous, in-process mechanism for interoperability between Node.js and .NET. You can use this mechanism to:

  • script Node.js from a .NET application (console app, ASP.NET, etc.)
  • script C# from a Node.js application on Windows, MacOS, and Linux
  • access MS SQL from Node.js using ADO.NET more...
  • use CLR multi-threading from Node.js for CPU intensive work more...
  • write native extensions to Node.js in C# instead of C/C++
  • integrate existing .NET components into Node.js applications

Read more about the background and motivations of the project here.

Follow @tjanczuk for updates related to the module.

Scripting CLR from Node.js

If you are writing a Node.js application, this section explains how you include and run CLR code in your app. It works on Windows, MacOS, and Linux.

What you need

Edge.js runs on Windows, Linux, and OSX and requires Node.js 8.x, 7.x, 6.x, as well as .NET Framework 4.5 (Windows), Mono 4.2.4 (OSX, Linux), or .NET Core 1.0.0 Preview 2 (Windows, OSX, Linux).

NOTE there is a known issue with Mono after 4.2.4 that will be addressed in Mono 4.6.

Windows

If you have both desktop CLR and .NET Core installed, read using .NET Core for how to configure Edge to use one or the other.

image

Linux

image

OSX

image

Docker

Edge.js is available as a Docker image on the tjanczuk/edgejs repository on Docker Hub. The image is based on Debian Trusty, and contains Node.js 6.3.0 x64, Mono 4.2.4 x64, .NET Core 1.0.0 Preview 2 x64 (dotnet-dev-1.0.0-preview2-003121), and Edge.js 6.5.1:

By default Edge uses Mono to execute CLR code:

> docker run -it tjanczuk/edgejs:6.5.1
> cd samples
> node 101_hello_lambda.js
.NET welcomes Node.js

Specify the EDGE_USE_CORECLR=1 envi

View on GitHub
GitHub Stars5.4k
CategoryDevelopment
Updated3d ago
Forks632

Languages

C++

Security Score

80/100

Audited on Mar 31, 2026

No findings