From ae451a5177680230757902734b8d33e88f0a23e7 Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 27 Apr 2017 17:22:07 +0200 Subject: [PATCH] changed the way configs are stored --- .gitignore | 2 +- README.md | 19 +++++-------------- config.json.example | 6 ++++++ js/mysql.js | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 config.json.example create mode 100644 js/mysql.js diff --git a/.gitignore b/.gitignore index cfb370a..e50e8f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/js/mysql.js +config.json # Logs logs diff --git a/README.md b/README.md index 87ab4f4..599977a 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,7 @@ # Paste -paste.tooth.yt +Website running on paste.tooth.yt -/js/mysql.js must export a mysql connection object like so -``` -var mysql = require('mysql'); - -var connection = mysql.createConnection({ - host: '127.0.0.1', - database: 'database', - user: 'username', - password: 'password' -}); - -module.exports = connection; -``` \ No newline at end of file +## Instructions +1. Copy **config.json.exmaple** to **config.json**. +2. Edit **config.json** and set mysql configuration. +3. Start **app.js**. diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..4f2e86c --- /dev/null +++ b/config.json.example @@ -0,0 +1,6 @@ +{ + "host": "127.0.0.1", + "database": "database", + "user": "user", + "password": "password" +} \ No newline at end of file diff --git a/js/mysql.js b/js/mysql.js new file mode 100644 index 0000000..649279a --- /dev/null +++ b/js/mysql.js @@ -0,0 +1,26 @@ +var mysql = require('mysql'); +var fs = require("fs"); + +var file = null; +var connection = null; + +try { + file = fs.readFileSync("./config.json"); +} +catch(exception) { + console.log(exception.toString()); +} + +if(file != null) { + var json = JSON.parse(file); + + connection = mysql.createConnection({ + host: json.host, + database: json.database, + user: json.user, + password: json.password + }); +} + + +module.exports = connection; \ No newline at end of file