From 7ee97d4771b0c8f8ab10a8f7f371f87b07e686fc Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Fri, 27 Jul 2018 22:35:28 -0700 Subject: [PATCH] getting proper max userId --- app.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index b84951b..4ad474a 100644 --- a/app.js +++ b/app.js @@ -19,7 +19,6 @@ app.get('/', function (req, res) { res.sendFile(__dirname + '/index.html'); }); - function handleDisconnect() { con = mysql.createConnection(db_config); // Recreate the connection, since // the old one cannot be reused. @@ -42,6 +41,16 @@ function handleDisconnect() { } handleDisconnect(); +app.get('/userid', function (req, res) { + var currUserId; + con.query('SELECT max(userId) from messages;', function (err, result, fields) { + if (err) throw err; + currUserId = result + 1; + }); + + res.json(currUserId); +}); + io.on('connection', function (socket) { console.log('Client connected: ' + socket.id);