From 1bfdecedf2e1dbb815d65d4d33afe08ac13635cb Mon Sep 17 00:00:00 2001 From: Rob Hedgpeth Date: Thu, 30 Jan 2020 13:12:23 -0800 Subject: [PATCH] Added dotenv --- Places/README.md | 19 +++++++++---------- Places/src/db.js | 12 +++++++++++- Places/src/package-lock.json | 5 +++++ Places/src/package.json | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Places/README.md b/Places/README.md index 497fbf5..fc3b214 100644 --- a/Places/README.md +++ b/Places/README.md @@ -101,17 +101,16 @@ export default GoogleApiWrapper({ })(MapContainer) ``` -2. Update the MariaDB connection configuration [here](src/db.js#L4). +2. Configure the MariaDB connection by [adding an .env file to the Node.js project](https://github.com/mariadb-corporation/mariadb-connector-nodejs/blob/master/documentation/promise-api.md#security-consideration). -```js -const pool = mariadb.createPool({ - host: 'localhost', - user:'ENTER_USERNAME_HERE', - password: 'ENTER_PASSWORD_HERE', - database: 'Places', - multipleStatements: true, - connectionLimit: 5 -}); +Example implementation: + +``` +DB_HOST= +DB_PORT= +DB_USER= +DB_PASS= +DB_NAME= ``` ### Build the code diff --git a/Places/src/db.js b/Places/src/db.js index 35fda89..d367d6e 100644 --- a/Places/src/db.js +++ b/Places/src/db.js @@ -1,6 +1,6 @@ var mariadb = require('mariadb'); +require('dotenv').config(); -// Local Connection const pool = mariadb.createPool({ host: 'localhost', user:'root', @@ -10,6 +10,16 @@ const pool = mariadb.createPool({ connectionLimit: 5 }); +const pool = mariadb.createPool({ + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASS, + port: process.env.DB_PORT, + database: process.env.DB_NAME, + multipleStatements: true, + connectionLimit: 5 +}); + module.exports={ getConnection: function(){ return new Promise(function(resolve,reject){ diff --git a/Places/src/package-lock.json b/Places/src/package-lock.json index a24de5a..5c0bd5b 100644 --- a/Places/src/package-lock.json +++ b/Places/src/package-lock.json @@ -200,6 +200,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/Places/src/package.json b/Places/src/package.json index 96fe478..5619afa 100644 --- a/Places/src/package.json +++ b/Places/src/package.json @@ -13,6 +13,7 @@ "dependencies": { "body-parser": "^1.19.0", "concurrently": "^5.0.0", + "dotenv": "^8.2.0", "express": "^4.17.1", "mariadb": "^2.1.2" }