@ -12,6 +12,15 @@ app.get('/', (req, res) => {
io.on('connection',(socket) => {
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, () => {
@ -1,10 +1,12 @@
{
"name": "nodejs-first-example",
"name": "A chat application",
"version": "1.0.0",
"description": "",
"description": "A simple 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"
}