Skip to content

Commit

Permalink
change database.js. add mysql config. add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarlosadm committed Mar 13, 2019
1 parent 21f9cbd commit 22f3c75
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 14 additions & 4 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
});

Expand Down
4 changes: 4 additions & 0 deletions config/mysql_user.json.model
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"user": "",
"password": ""
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 22f3c75

Please sign in to comment.