Using a .NET DLL in Node.js / serverside javascript

Dve picture Dve · Jan 11, 2011 · Viewed 54.5k times · Source

I have a pet project that is an online game, the entire game engine is written in C# and I would like to know if there is anyway I can call the functions of this existing assembly (.dll) from a solution built using Node.JS, Socket.IO, Express etc?

The game engine itself is pretty complete; tested and robust. I am hoping there is some neat way of exposing its functionality without too much overhead.

UPDATE:

To answer my own question a little.. I have ended building my own web socket server (based on the most current web socket protocol document). It is written in C# and compiled using Mono so that it can be hosted on a Linux box running mono and therefore (with a few tweaks) I can use my existing game engine.

UPDATE 2 A project that does exactly what I was originally looking for now exists - http://tjanczuk.github.io/edge/#/

UPDATE 3 Edge.js supporting node's last versions and .net core with a new edge-js package.

Support for Node.Js 6.x, 7.x, 8.x, 9.x, 10.x, 11.x Support for .NET Core 1.0.1 - 2.x on Windows/Linux/macOS. Support for Mono runtime 4.8.x - 5.x.

Can be installed from https://www.npmjs.com/package/edge-js

Answer

Tomasz Janczuk picture Tomasz Janczuk · Mar 26, 2013

Check out the edge.js project I started (http://tjanczuk.github.com/edge). It provides a mechanism for running .NET and node.js code in-process. Edge.js allows you to call .NET code from node.js and node.js code from .NET. It marshals data between .NET and node.js as well as reconciles the threading models between multi-threaded CLR and single threaded V8.

Using edge.js you can access islands of pre-existing .NET code from node.js, which seems to match your scenario.