forked from codingdud/webathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (34 loc) · 1013 Bytes
/
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
const express = require("express");
const mysql = require("mysql");
const dotenv =require("dotenv");
const path = require("path");
const exp = require("constants");
dotenv.config({path:'./.env'});
const app = express();
const db = mysql.createConnection({
host: process.env.host,
user: process.env.user,
password: process.env.password,
database: process.env.database
});
const publicDir = path.join(__dirname,'./public');
//console.log(__dirname);
app.use(express.static(publicDir));
//parse URL-encode bodies (as sent by html forms)
app.use(express.urlencoded({extended: false}));
// parse JSON bodies (as sent by html)
app.use(express.json());
app.set('view engine','hbs');
db.connect((error)=>{
if (error) {
console.log(error);
}else{
console.log("mysql conneted...");
}
});
// define routes ... url
app.use('/',require('./routes/pages'));
app.use('/auth',require('./routes/auth'));
app.listen(5001,()=>{
console.log("server started on port 5001");
});