We've recently upgraded from ASP.NET Core 1.0 to 3.1.
And in our code we're using the interface INodeServices and call its InvokeAsync method to activate some JavaScript library. After the upgrade to Core 3.1 the compiler complains that INodeServices is obsolete and should be replaced with 'Microsoft.AspNetCore.SpaServices.Extensions', but I couldn't find any type within this library that I could use instead of INodeServices, and I also coudn't find any documentation about it. What is the replacement for INodeServices.InvokeAsync in ASP.NET Core 3.1?
Thanks,
ashilon
Consider using this library instead https://github.com/JeringTech/Javascript.NodeJS
For more detailed informations and to see what other people did, i suggest you give a look at this thread https://github.com/dotnet/AspNetCore/issues/12890
I realize this is a late response, but I haven't seen a good response to this question. I don't think you need a library for this. From looking at the NodeServices disassembly, all it really does is launch the node process with your script.
Here is a summary of my solution for removing our dependency on NodeServices with no external library. We are using it for puppeteer and pdf generation, so my first argument is an URL and 2nd argument is path to chromium for puppeteer. You might want to add some thread-safety wrappers on the global variables.
private static Timer processTimer;
private static Process runningProcess;
private static void nodeServicesProcess() {
    var startInfo = new ProcessStartInfo("node"){
        Arguments = "C:\\abs_path_to\\start_script.js first_arg_to_script 2ndarg_to_script",
        UseShellExecute = false,
        RedirectStandardInput = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        WorkingDirectory = "C:\\abs_path_to_script_directory"
   };
    using (runningProcess = Process.Start(startInfo))
    {
        // Use your ILogger instances here
        runningProcess.ErrorDataReceived += new DataReceivedEventHandler((sender, ev) =>
        {
            Console.WriteLine($"stderr: {ev.Data}");
        });
        runningProcess.OutputDataReceived += new DataReceivedEventHandler((sender, ev) =>
        {
            Console.WriteLine($"stdout: {ev.Data}");
        });
        runningProcess.BeginOutputReadLine();
        runningProcess.BeginErrorReadLine();
        runningProcess.WaitForExit();
  }
}
// call this from your start application method
public static startNodeService() {
    processTimer = new Timer(nodeServicesProcess, null, 1000, Timeout.Infinite);
}
// call this on application end
public static stopNodeService() {
  if (processTimer != null) {
        if (runningProcess != null)
        {
            runningProcess.Kill();
        }
        processTimer.Dispose();
   }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With