sending a message in console when a user connects to the page

main
parent cf0e76f9a3
commit 18c3bb20e9

@ -1,5 +1,10 @@
<h1>Hello Dario from index.html file</h1> <html>
<body>
<p>Esta es una prueba de parrafo</p> <h1>Hello Dario from index.html file</h1>
<p>This is a text sample</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 Dario!</h1>'); // res.send('<h1> Hello Dario!</h1>');
res.sendFile(__dirname + '/index.html'); res.sendFile(__dirname + '/index.html');
}); });
io.on('connection', (socket) => {
console.log('A new user is connected');
});
server.listen(3333, () => { server.listen(3333, () => {
console.log('listen on port 3333'); console.log('listen on port 3333');
}); });

@ -9,6 +9,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