Repository: dkhd/node-group-chat Branch: master Commit: acf68199ff18 Files: 4 Total size: 3.5 KB Directory structure: gitextract_66nfv3wi/ ├── README.md ├── index.js ├── package.json └── views/ └── index.ejs ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ # Build A Group-Chat App in 30 Lines Using Node.js A simple and (hopefully) to-the-point tutorial to build your first group-chat application using Node.js in less than 30 lines of code. ## Running the program Run the program by using ```shell $ node index.js ``` ================================================ FILE: index.js ================================================ const express = require('express'); const app = express(); const http = require('http').Server(app); const io = require('socket.io')(http); app.get('/', function(req, res) { res.render('index.ejs'); }); io.sockets.on('connection', function(socket) { socket.on('username', function(username) { socket.username = username; io.emit('is_online', '🔵 ' + socket.username + ' join the chat..'); }); socket.on('disconnect', function(username) { io.emit('is_online', '🔴 ' + socket.username + ' left the chat..'); }) socket.on('chat_message', function(message) { io.emit('chat_message', '' + socket.username + ': ' + message); }); }); const server = http.listen(8080, function() { console.log('listening on *:8080'); }); ================================================ FILE: package.json ================================================ { "name": "node-simple-group-chat", "version": "1.0.0", "description": "A simple group chat built using Node.js and Socket.io", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Diky Hadna", "license": "ISC", "dependencies": { "ejs": "^2.6.1", "express": "^4.16.4", "socket.io": "^2.2.0" } } ================================================ FILE: views/index.ejs ================================================ Simple Group Chat on Node.js