Socket.io Chat App Using Websockets

Traversy Media · 408K views · 2016 · 35:33

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as a beginner-friendly socket.io walkthrough, and many askers cite it as the tutorial whose code they were following when they hit errors.

Recommended by 2 people across 2 different months, 2017 to 2020.

What it is

A 35-minute Traversy Media tutorial that builds a real-time chat app with Node.js, Express and socket.io, showing how to set up two-way communication over websockets. The presenter writes the server and a simple browser client from scratch, including usernames and message broadcasting.

What people said

Recommends Riad ZT · 2018-06 · Stack Overflow · on “Real Time API backend and frontend”

I think Express and Socket.io would be a good solution here. They work really well together and you would have crossbrowser checks and a lot of stuff you get with Socket.io out of the box. If you would use your own WebSockets you would have to write all this stuff, which is also a good thing if you know what you are doing. It can work really well and fast, of course it always depends how well you write your code. But the idea will work fine. Here you have a beginner friendly tutorial for socket.io: [this video] And here is one with MongoDB : [LINK]

Recommends Ognjen · 2020-07 · Stack Overflow · on “keep textarea update automatically on input - all around the world”

If I understood you correctly, you should look into WebSockets. Making AJAX calls to server for an update is a bad idea because if multiple people keep making AJAX calls for updates, it will take up all of your resources. I personally run NodeJS WebSocket server (socket.io) and make all communication via that server. This allows user to QUICKLY send information and for server to notify ALL connected users about those changes. Couple of tutorials for Socket.io : [LINK] [this video] [LINK]

Cites Probhas Ranjan Chanda 121-35-2 · 2017-05 · Stack Overflow · on “nodejs app running on node server but not showing any output”

hi i'm new in nodejs. var io = require('socket.io').listen(server); users = []; connections = []; server.listen(process.env.PORT || 3000); console.log('server running....on Pro'); app.get ('/', function(req, res){ res.sendFile(__dirname+'/index.html'); }); io.sockets.on('connections',function(socket){ connections.push(socket); console.log('connected: %s sockets is connected', connections.length); //Disconnet function socket.on('disconnect', function(data){ users.splice(users.indexOf(socket.username),1); updateUsernames(); connections.splice(connections.indexOf(socket),1); console.log('Disconneted: %s sockets connected', connections.length); }); //send messege socket.on('send massege', functi

Cites NewInThisWorld · 2017-06 · Stack Overflow · on “How to implement a Socket.io Chat App Using Websockets and Fetch usernames from database (mysqli)”

I am looking for a way to implement a chat function, I'm building a dating/friendship site for people with disabilities, it's coming along very nicely. since I am a beginner in the world of programming, I was looking for a way to create a simple chat function(ideally one that only functions when there is a mutual like or interest), so I found one on youtube-[ [this video] , its perfect, no page reloading etc. and it works like a charm when opening it on Localhost:3000, however I tried implementing it unto my website and it shows, but doesn't function, also this chat has a login function, but given that when clients are on my site they are already logged in. I would like to know how I can fetch my

Cites Dylbert · 2019-04 · Stack Overflow · on “"SyntaxError: Unexpected identifier" from import statement?”

for an assignment, I've created a chat app with Socket.io. I was able to create a functioning chat by following this tutorial: [this video] . However, the assignment gave me a specific chat server to use and I am struggling to do so. I am trying to import io and then use the io.connect() method to connect to the server url. The problem is, when I try to import, I get a "SyntaxError: Unexpected identifier". This is my code up until that line: var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); var users = []; var connections = []; import io from "socket.io-client"; The last line, 'import io from "socke

Cites Dylbert · 2019-04 · Stack Overflow · on “Connecting to a specific chat server URL with Socket.io?”

for an assignment, I am building a chat app with Socket.io. I was able to do so by following this tutorial: [this video] . However, for the assignment, I have to use a provided chat server which I am unsure how to do. I was provided with a chat service endpoint which looks like: " [LINK] " as well as an event name which looks like: "xxxxx/chat". I'm very new to JavaScript and I'm struggling to figure out where/how to implement this. Because I was following a video tutorial, this is how I began my server.js: var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); var users = []; var connections = []; serve

Cites King RG · 2019-06 · Stack Overflow · on “__dirname is not defined in NodeJS SocketIO”

So I'm trying to build from scratch a real time chat app using nodejs(socketio). Currently I am using laravel framework but to continue my project I needed to use nodejs too. This will help me to make my laravel project real time through the use of nodejs socket that's why I'm doing this tutorial from scratch. Just starting to learn this. Using this tutorial [this video] Here's my server.js code var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('socket.io').listen(server); users = []; connections = []; server.listen(process.env.PORT || 3000); console.log('Server running...'); app.get('/', function(req, res){ res.sendFile(__dirn

Cites Ian VanDooren · 2020-09 · Stack Overflow · on “Socket.io __dirname is not defined when trying to load on localhost”

I'm trying to build a basic chat function for a site and am following along with this tutorial... ( [this video] )... but socket.io doesn't seem to be loading on the page. I used the most recent CDN. I have a feeling my file path is off but I'm not quite sure how to repair it. I'm new, be gentle. <html> <head> <title>IO Chat</title> <link rel="stylesheet" href=" [LINK] "> <script src=" [LINK] " integrity="sha256-DrT5NfxfbHvMHux31Lkhxg42LY6of8TaYyK50jnxRnM=" crossorigin="anonymous"></script> <script src=" [LINK] "></script> <style> body { margin-top: 30px; } </style> </head> <body> <div class="container"> <div class="row"> <div class="col-md-4"> <div class="well"> <h3>Online Users</h3> <ul id="use