Am very new to node js and socket.io. I am using socket.io for a windows azure project. I have created an App.js which starts the socket.io server, but i dont know how to programatically run that script. I am able to run that script from command prompt like "node app.js" and the socket.io server starts and the client app is able to interact with socket.io server well.
I can also go to 127.0.0.1/App.js and the socket.io server starts.
But I want the script to automatically run as soon as i start the project in my VS. Any idea on how i can do that?
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
You would need to set up an entry point in the service defintiion that runs node.js, then when you run the project in the emulator, it will automatically spin up, somethign like:
Note that, you don't have to use vs for a node app, you can use the Windows Azure PowerShell to set up a node worker role to host your app, see:
http://www.windowsazure.com/en-us/develop/nodejs/tutorials/app-using-socketio/
for a tutorial pon setting up socket.io apps using PowerShell
Have you change your Handler "iisnode" ?
And edit Task of your WebRole in your .csdef :
This tutorial is a step by step guide to building and deploying nodeJS application on Azure http://www.windowsazure.com/en-us/develop/nodejs/tutorials/getting-started/
Well, depending on why you're using socket.io, worker role may be a better fit. WebSockets is not currently supported in WebRole, so you would need to set your transports to just xhr-polling if you used web role.
You can also consider using azure websites to host your app if you're just interested in a web role. You can check out my sample repo that has a socket.io chat app that can be deployed directly to azure websites:
http://github.com/markcowl/WebChatDefault-1