I have a node js script running Socket.io implementation in my web role. The only way i could find on how to start the node js script was running it in command prompt, so i created a background task in web role which runs the script in command prompt.
I set the property of "Copy To Output Directory" to "Copy If newer" for the node js file, cmd.exe and the node modules files and they are being generated in the bin folder. if i manually start the cmd.exe in the bin folder and run the command "node App.js", it works, the port on which the socket.io is listening is running. But when i run the command programatically like below it doesnt work.
It doesnt throw any error so i dont know if its a problem in my code or we cant start the node js script like this. Is there any way to find out if the command was executed properly or not? because no cmd prompt window was opened when the process starts. Any guidance, suggestions or ideas are deeply appreciated. Thanks
public class BackgroundThread
{
public static void Start()
{
var appRoot = Path.Combine(Environment.GetEnvironmentVariable("RoleRoot") + @"\", @"approot");
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = false;
psi.FileName = Path.Combine(appRoot, "bin", "cmd.exe");
psi.Arguments = "node app.js";
psi.UseShellExecute = false;
psi.WorkingDirectory = Path.Combine(appRoot, "bin");
try
{
Process p = Process.Start(psi);
}
catch (Win32Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine(ex.StackTrace);
Console.WriteLine(ex.Source);
Console.WriteLine(ex.ErrorCode);
}
}
}
EDIT:
Turned out iisnode can handle everything , i just had to put a rewrite code in web.config. From a sample azure node js application from here http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/ i got this rewrite code
<rewrite>
<rules>
<clear />
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="App.js" />
</rule>
</rules>
</rewrite>
Its starting the App.js automatically, but its re directing all my views to the App.js script. I guess it has something to do with the re write code i put above. What changes should i make to get the App.js running on start up and still be able to access my other html views?
Thanks