0

First i'd like to thank you for taking the time to try to help me.

I'm trying to do a web application online using node.js and socket.io for realtime. Here is my problem when i try my application in local it works but when i pushed it on heroku the server can't find my "herokuApp.heroku.com/socket.io/socket.io.js"

Of course i searched a lot for solve my problem but nothing here has solved it. Here is my files :

    var express = require('express');
var app = express(),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server),
    ent = require('ent'), // Disable HTML caracters (equal htmlentities in PHP)
    fs = require('fs');


    app.use(express.static(__dirname + '/public_html'));
    app.set('port', (process.env.PORT || 5000));
    server.listen(5000);


    io.sockets.on('connection', function (socket) {

        socket.on("newMsg", function(data){
            console.log("the client message: " + msg);});

    });


    app.get('/', function(request, response) {
      response.send('Hello World!');
    });

    app.listen(app.get('port'), function() {
      console.log('Node app is running on port', app.get('port'));
    });

and in my index.html

<script src="/socket.io/socket.io.js"></script>

I add some information like the server response when i push my commit : http://puu.sh/irF05/e1c648c627.png

and the structure of my files : http://puu.sh/irF8V/8240318ae6.png (the code above is from index.js and i don't use server.js)

Thanks you again for having read this, i'm not really familiar with node or socket so please excuse me if the solution is simple.

Exotit
  • 61
  • 5

1 Answers1

0

Make sure that socket.io.js is actually being pushed to the Heroku repository. Do a git status and make sure that it isn't untracked by git. Additionally, it might help if you post what your folder structure for this project looks like (at least the relevant files)

arafeek
  • 75
  • 5
  • thank you for your quick answer i added the information you asked me i also done the git status and my git isn't untracked – Exotit Jun 17 '15 at 00:30
  • So in that structure which folder is socket.io.js in? – arafeek Jun 17 '15 at 00:54
  • it is in node_modules\socket.io\node_modules\socket.io-client\socket.io.js but it would charge without the complete path I don't really understood why but it was working when i was on localhost:port – Exotit Jun 17 '15 at 00:58
  • Okay so assuming that script tag is in some sort of index.html file you're going to need to make sure you have a version of the library accessible on the client side (gets sent to the user's browser). So you are going to need a version in public_html. Optionally to rule out other possibilities, I'd change the script tag to something like ``. Which will reference the code at at the external CDN. – arafeek Jun 17 '15 at 01:01
  • i found this http://stackoverflow.com/questions/8689877/cant-find-socket-io-js and i think this is right but i can't figure out why the server don't distribute the version of io – Exotit Jun 17 '15 at 02:14