socket.io tested

main
Leonardo Mendoza 9 hours ago
parent 15241b3600
commit 298fb1b1d2

@ -0,0 +1,10 @@
<html>
<body>
<h1> Hello from the other side, at least I can say that i've tried </h1>
<p> to tell you I'm sorry, for breaking your heart </p>
<script src='/socket.io/socket.io.js'> </script>
<script> var socket = io(); </script>
</body>
</html>

@ -2,12 +2,18 @@ const express = require('express');
const app = express(); const app = express();
const http = require('http'); const http = require('http');
const server = http.createServer(app); const server = http.createServer(app);
const { Server } = require('socket.io');
const io = new Server(server);
app.get('/', (req, res) => { app.get('/', (req, res) => {
//res.send('<h1> Hello Leonard!</h1>'); //res.send('<h1> Hello Leonard!</h1>');
res.sendFile(__dirname + '/index.html'); res.sendFile(__dirname + '/index.html');
}); });
io.on('connection', (socket) => {
console.log('New user connected');
});
server.listen(3333, () => { server.listen(3333, () => {
console.log('Listen on port 3333'); console.log('Listen on port 3333');
}); });

@ -10,6 +10,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.22.3" "express": "^4.22.3",
"socket.io": "^4.8.4"
} }
} }

Loading…
Cancel
Save