Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06bb7f2

Browse files
committed
Added a node mysql example connection
1 parent 98c8904 commit 06bb7f2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
*/node_modules/
33
*.DS_Store
4+
*-secret.json
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var fs = require('fs');
2+
var mysql = require('mysql');
3+
4+
var config = JSON.parse(fs.readFileSync("config-secret.json"))
5+
6+
var connection = mysql.createConnection({
7+
host: config.host,
8+
user: config.user,
9+
password: config.password,
10+
port: config.port,
11+
database: config.database
12+
});
13+
14+
connection.connect();
15+
16+
connection.query('SELECT * FROM todos', function (error, results, fields) {
17+
console.log(results);
18+
});
19+
20+
connection.end();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "basic_mysql_connection",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"mysql": "^2.13.0"
13+
}
14+
}

0 commit comments

Comments
 (0)