0
votes

NodeJS 9.8.0
NodeJS client-side socket.io script not found. package.json:

..."dependencies": {
    "express": "latest",
    "socket.io": "latest"
}...

index.js:

var http = require("http"),
    express = require("express"),
    io = require("socket.io").listen(http),
    fs = require("fs");

var app = express();

var web = __dirname.split("\\").join("/")+"/web/";

app.get("/", function(req, res)
{
    res.sendFile(web + "index.html");
});
app.get("/:file", function(req, res)
{
    var file = web + req.param("file");
    var err = web + "error.html";
    fs.exists(file, function(exist)
    {
        if (exist) res.sendFile(file);
        else fs.exists(err, function(exist)
        {
            if (exist) res.sendFile(err);
            else res.send("<h1>Error! Page not found!</h1>");
        });
    });
});
// app.get("/*", function(req, res)
// {
    // var err = web + "error.html";
    // res.sendFile(err);
// });

io.sockets.on("connection", function(socket)
{
    console.log(socket);
});

http.createServer(app).listen(8080);

index.html:

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

and error: socket.io.js Failed to load resource: the server responded with a status of 404 (Not Found)

1

1 Answers

0
votes

If you go to http://socket.io/socket.io.js it says 404. The script has either moved or been removed.

They have links to download the script here https://cdnjs.com/libraries/socket.io

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

is telling your browser is to go to socket.io and get socket.io.js (using http or https) depending on how the web page you are at is loaded.

I am not sure if socket.io is supposed to replace that with something, but i doubt it based on reading their tutorial.

If you go to the github example you'll see they changed it to

 <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>

https://github.com/socketio/chat-example/blob/master/index.html