Skip to content

Commit

Permalink
Create Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffisgonnabefriend43546453423 committed Sep 13, 2024
1 parent d5eddce commit 6f1a48f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions live chat/Node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');

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

app.use(express.static('public'));

io.on('connection', (socket) => {
let username = '';

socket.on('login', (name) => {
username = name;
});

socket.on('message', (message) => {
io.emit('message', { username, message });
});
});

server.listen(3000, () => {
console.log('Server is running on port 3000');
});

0 comments on commit 6f1a48f

Please sign in to comment.