Show HN: ElectronCGI – Cross Platform .Net Core GUIs with Electron
ElectronCGI is a library that enables making requests from a NodeJs application that are served by a .Net application.
It uses the standard in/out streams for communication.
To use it install the electron-cgi npm package on you node application and the ElectronCgi.DotNet nuget package on your .Net console app.
Here's an example:
In NodeJs/Electron:
const { ConnectionBuilder } = require('electron-cgi');
const connection = new ConnectionBuilder()
.connectTo('dotnet', 'run', '--project', 'DotNetConsoleProjectWithElectronCgiDotNetNugetPackage')
.build();
connection.onDisconnect = () => {
console.log('Lost connection to the .Net process');
};
connection.send('greeting', 'John', theGreeting => {
console.log(theGreeting); // will print "Hello John!"
});
connection.close();
And in the .Net Console Application: using ElectronCgi.DotNet;
//...
static void Main(string[] args)
{
var connection = new ConnectionBuilder()
.WithLogging()
.Build();
// expects a request named "greeting" with a string argument and returns a string
connection.On<string, string>("greeting", name =>
{
return $"Hello {name}!";
});
// wait for incoming requests
connection.Listen();
}
[Blog post with extra information about ElectronCGI](https://www.blinkingcaret.com/2019/02/27/electron-cgi/) Very interesting - could this be used with another back end other than .net?
Currently the only implementation available is for .Net through the ElectronCgi.DotNet nuget package, but there's no reason for this not to work with other languages/runtimes (it relies on stdin/stdout that is available in all processes).
Did you have a particular language/runtime in mind?