-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
76 lines (62 loc) · 2.16 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// create an express app
const express = require("express");
const path = require("path");
const app = express();
var mysql = require('mysql');
// dotenv - store passwords & secure info
const dotenv = require('dotenv');
dotenv.config({ path: './.env' })
// all handlebar files must be in views directory
app.set('view engine', 'hbs');
const publicDirectory = path.join(__dirname, './public'); //__dirname is current directory
const hbs = require('hbs');
const partialsPath = path.join(__dirname, './views/partials');
hbs.registerPartials(partialsPath);
hbs.registerHelper('times', function(n, block) {
var accum = '';
for(var i = 0; i < n; ++i)
accum += block.fn("journal entriessssss");
console.log(accum);
return accum;
});
var db = mysql.createConnection({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
port: process.env.DATABASE_PORT,
//unix_socket: process.env.UNIX_SOCKET,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE
});
// require user to put phone number
db.connect(function(err) {
if (err) throw err;
console.log("Connected!");
// note for query in ticks we CANNOT put quotes!! Leave id, name, cell, etc. as is...
db.query(
`CREATE TABLE IF NOT EXISTS uofthacks.users(
id INT NOT NULL AUTO_INCREMENT ,
name VARCHAR(100) NOT NULL ,
cell VARCHAR(15) NOT NULL ,
email VARCHAR(100) NOT NULL ,
password VARCHAR(255) NOT NULL ,
PRIMARY KEY (id)
)
ENGINE = InnoDB;`,
function (err, result) {
if (err) throw err;
console.log("Login table users created");
});
});
// parse url-encoded bodies (from HTML forms)
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// use the express-static middleware - everything in the /public directory to be used (HTML, CSS, JS)
app.use(express.static(publicDirectory));
// get routes
app.use('/', require('./routes/pages'));
app.use('/auth', require('./routes/auth'));
app.use('/login', require('./routes/login'));
// app.use('/journals', require('./routes/journals'));
// start the server listening for requests
app.listen(process.env.PORT || 3001,
() => console.log("Server is running..."));