Home > Back-end >  cant connect app to node.js socket.io, html/css
cant connect app to node.js socket.io, html/css

Time:12-13

i trying like this, but anyway see only "cannot get /"

const app = express();
const server = require("http").createServer(app);

const io = require("socket.io")(server);

app.use(express.static(path.join(__dirname "/public")))
server.listen(5000);

CodePudding user response:

You need to require Server form socket.io (according to the get started). Try with this :

const app = express();
const server = require("http").createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);

app.use(express.static(path.join(__dirname "/public")))
server.listen(5000);

CodePudding user response:

here is my configuration:

const http = require("http");
const socketIo = require("socket.io");

const app= http.createServer((req, res) => {
  res.end("I am connected!");
});

//allowing cors for preventing localhost block
const io = socketIo(server, {
  cors: true,
  origins: ["localhost:3000"],
});

app.use(express.static(path.join(__dirname "/public")))

app.listen(8000);

  • Related