Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
@stcgoal 18101513 Node.JS and .NET Integrated. This grab the output from a nodejs and transform it into C# object
//sample JSON output that c# grab and transform
using Newtonsoft.Json;
//This grab the output from a nodejs and transform it into C# object
namespace dnc_nodejs_001
class Program
static void Main(string[] args)
// Console.WriteLine("Hello World!");
var proc = new System.Diagnostics.Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = "node";
proc.StartInfo.Arguments = "app.js";
proc.StandardInput.WriteLine("2 + 2;");
proc.StandardInput.WriteLine("setTimeout(function(){ process.exit();}, 10000).suppressOut;");
proc.OutputDataReceived += proc_OutputDataReceived;
static void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
string mydata = e.Data.ToString();
System.Console.WriteLine("The data received is : " + mydata);
MyMessage yourObject = JsonConvert.DeserializeObject<MyMessage>(mydata);
System.Console.WriteLine("Converted... \n"+
"Name: " + yourObject.Name +"\n"
+ "Phone: " + yourObject.Phone
public class MyMessage
public string Name { get; set; }
public string Phone { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.