2

I am using iisnode to run my node.js app. However, after about an hour, the node.exe process stops running (I need it running since I have a setInterval() method that pulls data from the database every few seconds). Any advice?

Also, if I set up my server with process.env.PORT, how do I connect to it using socket.io on the client-side? I understand that I have to use

io.configure(function () { 
    io.set("transports", ["xhr-polling"]); // no websockets
    io.set("polling duration", 10); 
    io.set("log level", 1); // no debug msg
});
victormejia
  • 1,174
  • 3
  • 12
  • 30

1 Answers1

5

This is a correct configuration for socket.io when the application is hosted in IIS using iisnode. On the client side, you connect to the server using the regular HTTP address of the endpoint exposed by IIS. Note that in order for socket.io to work out of the box, you need to host your node.js application as an IIS WebSite rather than a virtual directory within a web site: your app should be addressable with http://foobar.com/ rather than http://foobar.com/myapp/.

When you say the node.exe process stops running do you mean it is terminated and disappears or hangs? IIS will terminate worker processes (including any child processes they spawned, which is node.exe in this case) after a period of inactivity (when no HTTP requests arrive that target this server). The duration of that time period is configurable in the Application Pool settings.

If you rely on logic in your application that requires code to be run at intervals, IIS itself does not provide the best hosting model, as process lifetime is tied closely to HTTP messaging. You really need either a durable server (e.g. Windows Service, check out http://nssm.cc/), or some form of a web cron.

Tomasz Janczuk
  • 3,220
  • 21
  • 19
  • 1
    Hi Tomasz, I've configured the app pool to disable the idle timeout, but after 2 days it just stopped running. Any ideas? – victormejia Sep 10 '12 at 00:54
  • Same problem here. I've even created a HTTP landing page that the application is self-requesting via HTTP every 5 minutes, but it still gets shut down after a while. – Adam Gerthel Mar 16 '16 at 11:03