0

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

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for the answer, but i can only upvote it as i am still not able to start my node js scripts properly.
And btw are u sure that Web sockets are not supported in WebRole? because i was under the impression that IIS 8 supports web sockets?
WebSockets in non-.Net roles is technically possible, but not supported. If you are only using node.js, you are much better off with a worker role for now
0

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/

1 Comment

Ya, i did go through it but the whole process is done using Windows azure power shell, i work on VS 12 , i was hoping there would be some code with which i can start the App.js script on start up?
0

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

2 Comments

Am actually running my node js script and socket.io implementation in the web role. Should it be done only in worker role?
Again, worker role is a better for websockets for non-.Net roles currently. That should change in the very near future. Windows Azure PowerShell is really what you want to be using for this, it has better support for deploying non-.Net roles
0

Have you change your Handler "iisnode" ?

<!-- indicates that the server.js file is a node.js application 
to be handled by the iisnode module -->
<handlers>
  <add name="iisnode" path="App.js" verb="*" modules="iisnode" />
</handlers>
<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>

And edit Task of your WebRole in your .csdef :

<Task commandLine="node.cmd ..\App.js" executionContext="elevated" />

4 Comments

When i put the task in .csdef, the roles dont start, they hang, meaning the command couldnt be executed or something. Any idea what the issue might be?
Have you created a AzureNodeWebRole or AzureWebRole ? Read this to create a base nodeJS azure project : windowsazure.com/en-us/develop/nodejs/tutorials/getting-started
Azure web role from VS 2012. My node js file is just a small part of a big web role which is mostly written in c#. I just need to put this one node js file to implement socket.io. SO i dont think i should go for azure node web role, should i?
The NodeWebRole install for you the node executable, the startup node task, ... and your website can launch node program

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.