From 47c92234fe99b1469916e937293d6a2e154f45ba Mon Sep 17 00:00:00 2001 From: Jeffery R Date: Sat, 27 Jan 2018 11:06:48 -0500 Subject: [PATCH 1/2] Created skeleton for server --- README.md | 8 ++++++- googletrendsgame/server/server.js | 19 +++++++++++++++++ googletrendsgame/server/sql.js | 32 ++++++++++++++++++++++++++++ googletrendsgame/server/trendsAPI.js | 9 ++++++++ googletrendsgame/server/utils.js | 0 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 googletrendsgame/server/server.js create mode 100644 googletrendsgame/server/sql.js create mode 100644 googletrendsgame/server/trendsAPI.js create mode 100644 googletrendsgame/server/utils.js diff --git a/README.md b/README.md index 2d9382d..aca344e 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -GoogleTrendsGame +#GoogleTrendsGame + + +## Server dependencies +npm install mysql +npm install sanitizer +npm install google-trends-api \ No newline at end of file diff --git a/googletrendsgame/server/server.js b/googletrendsgame/server/server.js new file mode 100644 index 0000000..4143a13 --- /dev/null +++ b/googletrendsgame/server/server.js @@ -0,0 +1,19 @@ +var app = require('express')(); +var http = require('http').Server(app); +var io = require('socket.io')(http); + +const port = 3000; + +//Whenever someone connects this gets executed +io.on('connection', function(socket) { + console.log('A user connected'); + + //Whenever someone disconnects this piece of code executed + socket.on('disconnect', function () { + console.log('A user disconnected'); + }); +}); + +http.listen(port, function() { + console.log('listening on *:3000'); +}); \ No newline at end of file diff --git a/googletrendsgame/server/sql.js b/googletrendsgame/server/sql.js new file mode 100644 index 0000000..2797956 --- /dev/null +++ b/googletrendsgame/server/sql.js @@ -0,0 +1,32 @@ +// + +const mysql = require('mysql'); + +const sanitizer = require('sanitizer'); + +module.exports= + { + /** + * Function used to use insert statements into the database + * + * Don't worry, the input gets sanitized + * + * @param sqlStatement + * @return the id of the new record - if there is one + */ + insert : function(sqlStatement) + { + return new Promise(function(resolve, reject) + { + con.query(sanitizer.sanitize(sqlStatement), function (err, result) + { + if (err) + { + console.log(err); + resolve(0); + } + resolve(result.insertId); + }); + }) + } + }; \ No newline at end of file diff --git a/googletrendsgame/server/trendsAPI.js b/googletrendsgame/server/trendsAPI.js new file mode 100644 index 0000000..c3abe26 --- /dev/null +++ b/googletrendsgame/server/trendsAPI.js @@ -0,0 +1,9 @@ + + +module.exports= + { + getPopularity: function(word) + { + return 0; + } + }; \ No newline at end of file diff --git a/googletrendsgame/server/utils.js b/googletrendsgame/server/utils.js new file mode 100644 index 0000000..e69de29 From e7e609757afa3886c25f0abb43d87382a0bee4d3 Mon Sep 17 00:00:00 2001 From: Jeffery R Date: Sat, 27 Jan 2018 11:11:53 -0500 Subject: [PATCH 2/2] Updated docs --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aca344e..2096d85 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,15 @@ -#GoogleTrendsGame +# GoogleTrendsGame +Guess the trends beat your friends ## Server dependencies + + +```` +npm init +npm install express +npm install socket.io npm install mysql npm install sanitizer -npm install google-trends-api \ No newline at end of file +npm install google-trends-api +```` \ No newline at end of file