Approved Edge.js: V8 in Fougerite?

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
153
28
Los Angeles, California, USA
I am looking at Edge.js. It has a disadvantage compared to Jint. It requires installing node.exe for Windows on the Rust server host. But it's far more powerful than Jint. C# code called from Javascript is compiled on the spot. Javascript doesn't have to deal with types or anything like that. You just pass a block of C# code as a commented block of text, and Edge unwraps it and compiles it on the spot.

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

You can script C# from a Node.js process:
JavaScript:
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);
  });
You can also script Node.js from C#:
C#:
using System;
using System.Threading.Tasks;
using EdgeJs;

class Program
{
  public static async void 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)
  {
    Task.Run((Action)Start).Wait();
  }
}
Edge.js enables you to run Python and Node.js in-process.
Install edge and edge-py modules:
JavaScript:
npm install edge
npm install edge-py
In your server.js:
JavaScript:
var edge = require('edge');

var hello = edge.func('py', function () {/*
  def hello(input):
  return "Python welcomes " + input
    lambda x: hello(x)
  */});

hello('Node.js', function (error, result) {
  if (error) throw error;
    console.log(result);
  });
Run and enjoy:
Python:
$>node py.js
Python welcomes Node.js
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,098
4,863
113
At your house.
github.com
I am looking at Edge.js. It has a disadvantage compared to Jint. It requires installing node.exe for Windows on the Rust server host. But it's far more powerful than Jint. C# code called from Javascript is compiled on the spot. Javascript doesn't have to deal with types or anything like that. You just pass a block of C# code as a commented block of text, and Edge unwraps it and compiles it on the spot.

JavaScript:
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);
  });
C#:
using System;
using System.Threading.Tasks;
using EdgeJs;

class Program
{
  public static async void 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)
  {
    Task.Run((Action)Start).Wait();
  }
}
JavaScript:
npm install edge
npm install edge-py
JavaScript:
var edge = require('edge');

var hello = edge.func('py', function () {/*
  def hello(input):
  return "Python welcomes " + input
    lambda x: hello(x)
  */});

hello('Node.js', function (error, result) {
  if (error) throw error;
    console.log(result);
  });
Python:
$>node py.js
Python welcomes Node.js
Do you seriously have to use lambda at calling py code? Nah nah nah. I would rather stay at the original Python.