I wasn't sure if this is appropriate on the Ubuntu exchange or here but it is mostly code related i believe.
So I have created a neat working little web-chat application using socket.io which I've been developing on my Win10 pc using Git-bash and running it on my localhost with node.js and everything has been working just fine.
Thus I have come to a point where I would like to try out my app on my web-server.
Lets get more detailed what my Problems are:
- I am unsure of how my server.js file should listen or open up the ports so to speak. I have tried looking in the sockets.io chat example and tried their method yet the '../..' module leaves me confused.
- Following the express.js site tutorial I actually get my server to respond
listening on port 3000yet my website returns the nosocket.io/socket.io.jsfound. - this and this just lead to another localhost tutorial
In Short I have come to the point where when i do node server.js It seems to start listening here's the code to that part:
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
var port = process.env.PORT || 3000;
app.get ('/', function(req,res) {
res.sendFile(__dirname + '/index.html');
});
app.use("/static", express.static('./static/'));
server.listen(3000);
But now the problem is is that my html file cannot seem to find the socket.io/socket.io.js file, even though i have installed sockets.io, i consulted to this stack question which should fix it, but it didnt thus leads me to believe theres a thicker more server side issue?
Versions i am using:
express: **4.16.4**;
node : **10.15.0**;
npm : **6.4.1**;
socket : **2.2.0**;
EDIT: Added my html code snips
html
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script src="static/index.js"></script>
var io = require('socket.io').listen(server);line from? In my opinion, it should bevar io = require('socket.io')(server);.socket.ioimplementation to be honest. Right now, I have a running one working where I make Express listen on a specific port (say,server.listen(1111)) and socket.io on another one (io.listen(3000)). If this can be used of any use to you ...var server = http.createServer(app);,var io = require('socket.io')(server);andserver.listen(port), I simply addedio.listen(3000). Both Express and socket.io listen to their own port and everything runs smoothly. Could you add your client code to see your<script src>line?http://192.168.220.11:3000/socket.io/socket.io.json my PC and I see the script just fine. I did notice a small error though: going tohttp://192.168.220.11:3000results in an error because express is trying to serve...pathindex.htmlinstead of...path/index.html; you need to add a slash/index.htmlto your/route.i though have a domain thus i cant change it like thatnot sure what you mean, you can just go tohttp://example.com:3000Don't you have to do that anyway to see the index file? The raspberry also has a hostname; everything works just as well when I go to raspberry.router.box:3000