diff --git a/index.html b/index.html
index 5f51ffe..674a682 100644
--- a/index.html
+++ b/index.html
@@ -1,9 +1,38 @@
+
+
+ Chat app
+
- Hello Dario from index.html file
- This is a text sample
+ A new Chat App
+
+
+
-
+
diff --git a/index.js b/index.js
index cbe9294..f2b84c0 100644
--- a/index.js
+++ b/index.js
@@ -12,6 +12,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 disconnected");
+ });
+ // 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 06e4076..d306d14 100644
--- a/package.json
+++ b/package.json
@@ -1,15 +1,20 @@
{
"name": "nodejs-first-example",
"version": "1.0.0",
- "description": "first node js example to see how it works",
+ "description": "A simple chat application using express and socket.",
"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"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.22.3",
"socket.io": "^4.8.4"
+ },
+ "devDependencies": {
+ "nodemon": "^3.1.14"
}
}