index.html

main
Angelus Vela 4 weeks ago
parent 2b4072a6b7
commit 5b623c8a9c

@ -12,6 +12,15 @@ app.get('/', (req, res) => {
io.on('connection',(socket) => { io.on('connection',(socket) => {
console.log ('A new user is connected'); console.log ('A new user is connected');
//disconect
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, () => { server.listen(3333, () => {

@ -1,10 +1,12 @@
{ {
"name": "nodejs-first-example", "name": "A chat application",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "A simple chat application using express and socket.io",
"main": "index.js", "main": "index.js",
"scripts": { "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": [], "keywords": [],
"author": "", "author": "",
@ -12,5 +14,8 @@
"dependencies": { "dependencies": {
"express": "^4.22.3", "express": "^4.22.3",
"socket.io": "^4.8.4" "socket.io": "^4.8.4"
},
"devDependencies": {
"nodemon": "^3.1.14"
} }
} }

Loading…
Cancel
Save