title: Error running a socket.io node.js app on Heroku
body: <p>I've deployed succesfully but when I run my app I get this error in my browser.</p>
  
  <p><img src="https://i.stack.imgur.com/mtvmH.jpg" alt="enter image description here"></p>
  
  <p>These are what my heroku logs says:</p>
  
  <pre><code>C:\Users\Shekhar\heroku&gt;heroku logs
  2013-09-18T19:50:39.552663+00:00 heroku[api]: Enable Logplex by shekharsumanrock
  @gmail.com
  2013-09-18T19:50:39.574021+00:00 heroku[api]: Release v2 created by shekharsuman
  rock@gmail.com
  2013-09-18T19:51:51+00:00 heroku[slug-compiler]: Slug compilation started
  2013-09-18T19:52:12.810160+00:00 heroku[api]: Scale to web=1 by shekharsumanrock
  @gmail.com
  2013-09-18T19:52:12.838111+00:00 heroku[api]: Add PATH config by shekharsumanroc
  k@gmail.com
  2013-09-18T19:52:12.866467+00:00 heroku[api]: Release v3 created by shekharsuman
  rock@gmail.com
  2013-09-18T19:52:12.914733+00:00 heroku[api]: Deploy 36856b3 by shekharsumanrock
  @gmail.com
  2013-09-18T19:52:12.943415+00:00 heroku[api]: Release v4 created by shekharsuman
  rock@gmail.com
  2013-09-18T19:52:13+00:00 heroku[slug-compiler]: Slug compilation finished
  2013-09-18T19:52:15.273489+00:00 heroku[web.1]: Starting process with command `n
  ode app.js`
  2013-09-18T19:52:15.912133+00:00 heroku[web.1]: Starting process with command `n
  ode app.js`
  2013-09-18T19:52:16.112156+00:00 app[web.1]: info: socket.io started
  2013-09-18T19:52:16.112156+00:00 app[web.1]: Server running at http://localhost:
  5000/
  2013-09-18T19:52:19.292035+00:00 app[web.1]: Server running at http://localhost:
  5000/
  2013-09-18T19:52:19.292035+00:00 app[web.1]: info: socket.io started
  2013-09-18T19:53:16.461372+00:00 heroku[web.1]: Stopping process with SIGKILL
  2013-09-18T19:53:16.461211+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web
  process failed to bind to $PORT within 60 seconds of launch
  2013-09-18T19:53:17.545639+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web
  process failed to bind to $PORT within 60 seconds of launch
  2013-09-18T19:53:17.545980+00:00 heroku[web.1]: Stopping process with SIGKILL
  2013-09-18T19:53:17.710781+00:00 heroku[web.1]: Process exited with status 137
  2013-09-18T19:53:18.938730+00:00 heroku[web.1]: Process exited with status 137
  2013-09-18T19:53:20.623319+00:00 heroku[web.1]: Starting process with command `n
  ode app.js`
  2013-09-18T19:53:22.046545+00:00 app[web.1]: info: socket.io started
  2013-09-18T19:53:22.046545+00:00 app[web.1]: Server running at http://localhost:
  5000/
  2013-09-18T19:54:22.301236+00:00 heroku[web.1]: Error R10 (Boot timeout) -&gt; Web
  process failed to bind to $PORT within 60 seconds of launch
  2013-09-18T19:54:22.301533+00:00 heroku[web.1]: Stopping process with SIGKILL
  2013-09-18T19:54:24.052821+00:00 heroku[web.1]: Process exited with status 137
  2013-09-18T19:53:17.722653+00:00 heroku[web.1]: State changed from crashed to st
  arting
  2013-09-18T19:53:17.721912+00:00 heroku[web.1]: State changed from starting to c
  rashed
  2013-09-18T19:54:35.879665+00:00 heroku[router]: at=error code=H10 desc="App cra
  shed" method=GET path=/ host=stark-temple-8404.herokuapp.com fwd="117.198.13.71"
   dyno= connect= service= status=503 bytes=
  2013-09-18T19:54:36.881441+00:00 heroku[router]: at=error code=H10 desc="App cra
  shed" method=GET path=/favicon.ico host=stark-temple-8404.herokuapp.com fwd="117
  .198.13.71" dyno= connect= service= status=503 bytes=
  </code></pre>
  
  <p>What mistake am I doing?</p>
  
  <p>-------EDIT-------</p>
  
  <p><strong>app.js file</strong></p>
  
  <pre><code>var app = require('http').createServer(handler)
  , io = require('socket.io').listen(app)
  , fs = require('fs')
  
  function handler(req, res) {
      if ('GET' == req.method &amp;&amp; '/images' == req.url.substr(0, 7) &amp;&amp; '.jpg' == req.url.substr(-4)) {
          fs.stat(__dirname + req.url, function (err, stat) {
              if (err || !stat.isFile()) {
                  res.writeHead(404);
                  res.end('Not Found');
                  return;
              }
          serve(__dirname + req.url, 'application/jpg');
      });
      } 
      else if ('GET' == req.method &amp;&amp; '/' == req.url) {
          serve(__dirname + '/index.html', 'text/html');
      } 
      else if ('GET' == req.method &amp;&amp; '.css' == req.url.substr(-4)) {
          serve(__dirname + req.url, 'text/css');
      }
      else if ('GET' == req.method &amp;&amp; '.ico' == req.url.substr(-4)) {
          console.log("ICON has been called");
          serve(__dirname + req.url, 'image/x-icon');
      } 
      else if ('GET' == req.method &amp;&amp; '.js' == req.url.substr(-3)) {
          serve(__dirname + req.url, 'application/javascript');
      } 
      else if ('GET' == req.method &amp;&amp; '.png' == req.url.substr(-4)) {
          serve(__dirname + req.url, 'image/png');
      }
      else {
          res.writeHead(404);
          res.end('Not found');
      }
      function serve (path, type) {
          res.writeHead(200, { 'Content-Type': type });
          fs.createReadStream(path).pipe(res);
      }
  };
  
  console.log('Server running at http://localhost:5000/');
  app.listen(5000);
  
  
  io.configure(function () { 
    io.set("transports", ["xhr-polling"]); 
    io.set("polling duration", 10); 
  });
  
  io.sockets.on('connection', function (socket) {
    io.sockets.emit('this', { will: 'be received by everyone'}); //This will be received by everyone
    socket.emit('news', { hello: 'world' }); //This will be received by none but one
    socket.on('my other event', function (data) {
      console.log(data);
    });
    socket.on('disconnect', function () {
      io.sockets.emit('user disconnected');
    });
    socket.broadcast.emit('user connected'); //This will be received by everyone but one who initiates it
  
  
  
    socket.on('set nickname', function (name) {
      socket.set('nickname', name, function () {
        socket.emit('ready');
      });
    });
  
    socket.on('msg', function () {
      socket.get('nickname', function (err, name) {
        console.log('Chat message by ', name);
      });
    });
  });
  </code></pre>
  
  <p><strong>index.html file</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;YAY!!&lt;/title&gt;
  &lt;script src="/socket.io/socket.io.js"&gt;&lt;/script&gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
  &lt;script&gt;
    //var socket = io.connect('http://localhost');
  
    var socket = io.connect(window.location.hostname);
  
    socket.on('news', function (data) {
      console.log(data);
      socket.emit('my other event', { my: 'data' });
    });
    socket.on('this', function(data)  {
        console.log("This has been received "+data.will);
    });
    socket.emit('set nickname','Shekhar');
    socket.on('ready', function(data) {
        console.log("Name Set");
    });
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="box1"&gt;What's up?&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>