title: Starting the node js script from command prompt programatically
body: <p>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. </p>
  
  <p>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.</p>
  
  <p>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</p>
  
  <pre><code>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);
          }       
      }
  
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>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 <a href="http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/" rel="nofollow">http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/</a> i got this rewrite code</p>
  
  <pre><code>&lt;rewrite&gt;
    &lt;rules&gt;
      &lt;clear /&gt;
      &lt;rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"&gt;
        &lt;match url="iisnode.+" negate="true" /&gt;
        &lt;conditions logicalGrouping="MatchAll" trackAllCaptures="false" /&gt;
        &lt;action type="Rewrite" url="App.js" /&gt;
      &lt;/rule&gt;
    &lt;/rules&gt;
  &lt;/rewrite&gt;
  </code></pre>
  
  <p>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? </p>
  
  <p>Thanks</p>