From fe51c3ef1dc55ca7fd59d29f005ea9241807c852 Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Fri, 23 Oct 2026 08:22:39 -0600 Subject: [PATCH] emiting events --- index.html | 36 +++++++++++++++++++++++++++++++++--- index.js | 9 +++++++++ package.json | 11 ++++++++--- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 46873a1..d761979 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,39 @@ + + + Chat App + -

Hello Marx from index.html file

-

This is some text

+

A new Chat App

+ + +
+ +
+ - + diff --git a/index.js b/index.js index 2cd03b2..8f2f814 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,15 @@ app.get('/', (req, res) => { io.on('connection', (socket) => { console.log('A new user is connected'); + // disconnect + socket.on('disconnect', () => { + console.log("A user has been disconnect"); + }); + // more functions + socket.on('chat message', (msg) => { + console.log(msg); + io.emit('chat message', msg); + }); }); server.listen(3333, () => { diff --git a/package.json b/package.json index 01346ab..2d4a966 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,12 @@ { - "name": "nodejs-first-example", + "name": "A chat application", "version": "1.0.0", - "description": "", + "description": "A simpel chat application using express and socket.io", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js", + "dev": "nodemon index.js" }, "keywords": [], "author": "", @@ -12,5 +14,8 @@ "dependencies": { "express": "^4.22.3", "socket.io": "^4.8.4" + }, + "devDependencies": { + "nodemon": "^3.1.14" } }