diff --git a/.gitignore b/.gitignore index bd1c9f8..f348b95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config/mysql_user.json + # Created by https://www.gitignore.io/api/node,eclipse,webstorm,intellij,sublimetext,visualstudiocode # Edit at https://www.gitignore.io/?templates=node,eclipse,webstorm,intellij,sublimetext,visualstudiocode diff --git a/config/database.js b/config/database.js index 556cef4..21d14ca 100644 --- a/config/database.js +++ b/config/database.js @@ -1,9 +1,19 @@ var mysql = require('mysql2'); +var fs = require('fs'); +var path = require('path'); + +var BUFFER = bufferFile('mysql_user.json'); + +function bufferFile(relPath) { + return fs.readFileSync(path.join(__dirname, relPath)); +} + +var parsed = JSON.parse(BUFFER.toString()); var con = mysql.createConnection({ host: "localhost", - user: "root", - password: "123" + user: parsed.user, + password: parsed.password }); con.query("CREATE DATABASE IF NOT EXISTS stock", @@ -15,8 +25,8 @@ con.query("CREATE DATABASE IF NOT EXISTS stock", var con = mysql.createConnection({ host: "localhost", - user: "root", - password: "123", + user: parsed.user, + password: parsed.password, database: "stock" }); diff --git a/config/mysql_user.json.model b/config/mysql_user.json.model new file mode 100644 index 0000000..a46cffa --- /dev/null +++ b/config/mysql_user.json.model @@ -0,0 +1,4 @@ +{ + "user": "", + "password": "" +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..709c54f --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +### instruções + +- copie o arquivo *config/mysql_user.json.model* para *config/mysql_user.json* +- abra o arquivo copiado *config/mysql_user.json* e edite os campos *user* e *password* +- talvez você precise criar a base *stock* e conceder privilégios de acesso ao usuário usado na aplicação. \ No newline at end of file