Bridge between .net standard 2.0 and node.js for pre/server side rendering or node specific tasks.
Nodeservices from microsoft spawn a new process almost every new request. And sometimes in situations where you need to persist the process for configuration purposes or just for plain performance, you can't with nodeservices. Nodeservices also supports streams where I choose to skip that, if that is needed check the implementation here and create a pr.
- node >= 10.5 (prefer 12.x)
- .net standard 2.0
services.AddNodeBridge(options => {
options.Workingdirectory = ""; // Optional: base directory for your node files. Default: Working directory of your project.
options.Instances = 1; // Optional: Number of worker threads to spawn. Default: Number of cores of your system.
options.Logger = loggerInstance; // Optional: Attach any logger that implements the ILogger interface. Default: standard ILogger.
options.Port = 3000; // Optional: Port for the node bridge to listen on. Default: Random port.
});
public class ValuesController : Controller
{
private readonly Bridge _bridge;
public ValuesController(Bridge bridge)
{
_bridge = bridge;
}
public async Task<IActionResult> Index()
{
// Note!
// Any exported function should return a promise.
var result = _bridge.Invoke("file.js", "test", "hello"); // Will invoke function test in file.js with hello as the first argument.
ViewBag.result = result;
return View();
}
}
Copyright © 2020 Colonelbundy.
This project is MIT licensed.