const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const path = require('path');

const app = express();
const server = http.Server(app);
const io = socketIO(server);

// Exposes the folder frontend
app.use(express.static(path.join(__dirname, 'frontend', 'dist')));

io.on('connection', function (socket) {
    //Welcome a new user
	//Prompt user for username clientside
	//Welcome user in chat with name
	socket.on('name', function(name){
	io.emit('welcome', name+' joined the chat');
	socket.on('msg', function (data) {
        //New message
		var username = data.user;
		var message = data.msg;
		io.emit('newmsg', {
		user : username,
		msg : message
		});
	});
	})
    
});

server.listen(process.env.PORT || 3000, () => {
	console.log(`Server is listening on port: ${server.address().port}`);
});

@@ -358,36 +358,12 @@
 ) %7B%0A
-    //Welcome a new user%0A
 %09//
+ 
 Prom
@@ -397,16 +397,17 @@
 side%0A%09//
+ 
 Welcome 
@@ -452,182 +452,579 @@
 e', 
-function(name)%7B%0A%09io.emit('welcome', name+' joined the chat');%0A%09socket.on('msg', function (data) %7B%0A        //New message%0A%09%09var username = data.user;%0A%09%09var message = data.msg;%0A
+name =%3E %7B%0A%09%09// Save the username and join timestamp%0A%09%09socket.meta = %7B%0A%09%09%09username: name,%0A%09%09%09joinedAt: Date.now()%0A%09%09%7D;%0A%09%09%0A%09%09// Emit a join event%0A%09%09io.emit('join', %7B%0A%09%09%09user: socket.meta.username,%0A%09%09%09time: socket.meta.joinedAt%0A%09%09%7D);%0A%09%09%0A%09%09//New message%0A%09%09socket.on('msg', msg =%3E %7B%0A%09%09%09const timestamp = Date.now();%0A%09%09%09// Send the message to all users%0A%09%09%09io.emit('msg', %7B%0A%09%09%09%09user : socket.meta.username,%0A%09%09%09%09msg : msg,%0A%09%09%09%09time: timestamp%0A%09%09%09%7D);%0A%09%09%7D);%0A%09%09%0A%09%09// Handle disconnect%0A%09%09socket.on('disconnect', reason =%3E %7B%0A%09%09%09const timestamp = Date.now();%0A%09%09%09// Emit a leave event%0A%09
 %09%09io
@@ -1034,53 +1034,124 @@
 it('
-newmsg
+leave
 ', %7B%0A
+%09%09
 %09%09user
- 
 : 
-username,%0A%09%09msg : message
+socket.meta.username,%0A%09%09%09%09time: timestamp,%0A%09%09%09%09duration: timestamp - socket.meta.joinedAt%0A%09%09%09%7D);
 %0A%09%09%7D
@@ -1162,17 +1162,8 @@
 %7D);%0A
-%09%7D)%0A    %0A
 %7D);%0A

Update web_server.js