Search code examples
javascriptnode.jsherokunodejitsu

Node.js Hosting w/Multiple Ports, or wrong practice?


I'm trying to figure out the best workflow for producing an app I can have hosted on one of the various public Node environments. The sticking point seems to be that my app opens two ports: one for HTTP and another for WebSockets.

Here's the code which executes great on my own system, but runs into EADDRINUSE errors on hosted services. (NOTE: this is regardless of changes in port number)

CODE: http://pastebin.com/zjJKbj2U

QUESTION: Am I wrong in my approach of searching for a Node service that provides this ability, or should I be going about this in a different way?


Solution

  • Do you have a specific reason you think you need a different port for HTTP and web sockets? They are designed to work fine using the same port, and as you are seeing, things are much easier if you just use them that way. Your app can access both regular web resources as well as opening a web socket connection to the server at the same time over a single port. There's an example of using express for your web site and ws for websockets on the same port here.