Skip to content

Bridge between .net standard and node.js for pre/server side rendering or node specific tasks.

License

Notifications You must be signed in to change notification settings

ColonelBundy/Nodebridge

Repository files navigation

⛓️ Nodebridge ⛓️

Nuget Package

Bridge between .net standard 2.0 and node.js for pre/server side rendering or node specific tasks.

❔ Why use this instead of nodeservices from Microsoft?

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.

📄 Prerequisites

  • node >= 10.5 (prefer 12.x)
  • .net standard 2.0

🚀 Usage

In Startup -> ConfigureServices

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

Usage in controllers

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

📝 License

Copyright © 2020 Colonelbundy.
This project is MIT licensed.

About

Bridge between .net standard and node.js for pre/server side rendering or node specific tasks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published