Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# .env.example
NODE_ENV=development
PORT=8000

# Set your database connection information here
DATABASE_HOST=192.168.56.111
DATABASE_NAME=app1
DATABASE_USER=homestead
DATABASE_PASSWORD=secret
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
package-lock.json
package-lock.json
.env
15 changes: 10 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
const app = require('express')();
const mysql = require('mysql');
const bodyParser = require('body-parser');

//Use dotenv to read .env vars into Node
require('dotenv').config();

const routes = require('./routes');

// the mysql.createConnection function takes in a configuration object which contains host, user, password and the database name.
const db = mysql.createConnection ({
host: 'localhost',
user: 'root',
password: 'root',
database: 'app1'
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME
});


// connect to database
db.connect((err) => {
if (err) {
Expand All @@ -22,7 +27,7 @@ db.connect((err) => {

global.db = db;

const PORT = process.env.PORT || 3000;
const PORT = process.env.PORT || 8000;

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // parse form data client
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"dotenv": "^6.2.0",
"ejs": "^2.6.1",
"express": "^4.16.4",
"mysql": "^2.16.0",
Expand Down