Overview
Installation
Usage
Projects Using this Package
Contributing
About
Jering.Redist.NodeJS places NodeJS executables in your application's output directory.
This package is automatically updated. Package versions correspond to NodeJS versions.
Using Package Manager:
PM> Install-Package Jering.Redist.NodeJS
Using .Net CLI:
> dotnet add package Jering.Redist.NodeJS
NodeJS executables for 4 kinds of operating systems are copied to the output directory of your project:
/<project path>/bin/<configuration>/<target framework>
├──<your application>.dll
|
├──miscellaneous dlls
|
└──/NodeJS
|
├──/linux-x64
| └──node
|
├──/osx-x64
| └──node
|
├──/win-x64
| └──node.exe
|
└──/win-x86
└──node.exe
We recommend using Jering.Javascript.NodeJS to invoke javascript in NodeJS. Jering.Javascript.NodeJS starts and manages NodeJS processes for you, reusing them indefinitely to avoid the overhead of starting and killing NodeJS processes.
If you prefer to manage your own NodeJS process, here's how you can locate a suitable executable:
public Process CreateNodeJSProcess(string args)
{
string runtimeIdentifier;
bool isWindows;
// Determine OS
if (isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
runtimeIdentifier = "win-";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
runtimeIdentifier = "linux-";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
runtimeIdentifier = "osx-";
}
else
{
// Jering.Redist.NodeJS doesn't provide an executable suitable for the current machine
return null;
}
// Determine architecture
if (RuntimeInformation.OSArchitecture == Architecture.X64)
{
runtimeIdentifier += "x64";
}
else if (isWindows && RuntimeInformation.OSArchitecture == Architecture.X86)
{
runtimeIdentifier += "x86";
}
else
{
// Jering.Redist.NodeJS doesn't provide an executable suitable for the current machine
return null;
}
// Create executable path
string executablePath = Path.Combine(Directory.GetCurrentDirectory(), "NodeJS", runtimeIdentifier, "node");
// Start process
return Process.Start(executablePath, args);
}
Do note that logic in the example for starting a process is trivialized. You'd typically need at least exception and output (stdout/stderr) handling. Refer to Microsoft's documentation for the Process type for more information.
Jering.Javascript.NodeJS - Invoke Javascript in NodeJS, from C#.
Contributions are welcome!
Follow @JeringTech for updates and more.