bradtraversy / chatcord

Realtime chat app with rooms
1.18k stars 1.15k forks source link

Uncaught ReferenceError: io is not defined #4

Closed usmailaabdoul closed 4 years ago

usmailaabdoul commented 4 years ago

Hello while following your tutorial at the step where Brad adds the socket.io script in the chat.html file and console.log in main.js (13:43 minute in the tutorial video) after testing it out on the web i keep having this error pls i don't know if i could get some help this is my screen any suggestion i was really hoping to follow the tutorial but this is setting me back thanks in advance

Screen Shot 2020-03-27 at 21 18 07
JBrLloyd commented 4 years ago

Hi @usmailaabdoul! Would you mind sharing your server.js? I'm guessing without knowing the contents of your server.js, but do you have app.listen instead of server.listen? as server = http.createServer is the instance that is initialised with the socketio library

const express = require('express');
const socketio = require('socket.io');

const formatMessage = require('./utils/messages');
const constants = require('./utils/constants');

const app = express();
const server = http.createServer(app);
const io = socketio(server);

server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
usmailaabdoul commented 4 years ago

Hello @JBrLloyd Thanks for your response i actually used app.listen instead of server.listen, been used to using to app.listen so couldn't see it to be the mistake, changing it fixed the problem thanks so much for your help 😊