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)