changed the way configs are stored
This commit is contained in:
parent
ce937728a5
commit
ae451a5177
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
/js/mysql.js
|
config.json
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|||||||
19
README.md
19
README.md
@ -1,16 +1,7 @@
|
|||||||
# Paste
|
# Paste
|
||||||
paste.tooth.yt
|
Website running on paste.tooth.yt
|
||||||
|
|
||||||
/js/mysql.js must export a mysql connection object like so
|
## Instructions
|
||||||
```
|
1. Copy **config.json.exmaple** to **config.json**.
|
||||||
var mysql = require('mysql');
|
2. Edit **config.json** and set mysql configuration.
|
||||||
|
3. Start **app.js**.
|
||||||
var connection = mysql.createConnection({
|
|
||||||
host: '127.0.0.1',
|
|
||||||
database: 'database',
|
|
||||||
user: 'username',
|
|
||||||
password: 'password'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = connection;
|
|
||||||
```
|
|
||||||
|
|||||||
6
config.json.example
Normal file
6
config.json.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"host": "127.0.0.1",
|
||||||
|
"database": "database",
|
||||||
|
"user": "user",
|
||||||
|
"password": "password"
|
||||||
|
}
|
||||||
26
js/mysql.js
Normal file
26
js/mysql.js
Normal file
@ -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;
|
||||||
Loading…
x
Reference in New Issue
Block a user