Client side cannot find socket.io.js

I read all the other posts on this topic, but I can not find the answer for my problem. I have an Express server running by default or 5000 (process.env.PORT || 5000). Then I added socket.io, but the client side cannot find the socket.io.js file. After some tests, I assume there is a problem with some port conflicts or something else. Here is my server code:

var express = require('express'),
    app = express(),
    bodyParser = require('body-parser'),
    server = require('http').createServer(app),
    io = require('socket.io').listen(server);

    app.set('port', (process.env.PORT || 5000));

Edit: client side material: enter image description here

Edit 2: Also, I don't think this is important, but I am testing this on the local Heroku server.

Edit 3: Directory structure:

--api
--images
--node_modules
--scripts
--pages
    main_page.ejs
--styles
composer
index.js 
npm-debug
package

Edit 4: Bump

+4
source share
1

Socket.IO /socket.io/, socket.io.js. , virtual socket.io.js , 404.

:

app.set('port', (process.env.PORT || 5000));
app.listen(app.get('port', function() { ... });

:

app.set('port', (process.env.PORT || 5000));
server.listen(app.get('port'), function() { ... });

Express /socket.io/ .

+2

Source: https://habr.com/ru/post/1670207/


All Articles