-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (38 loc) · 1.77 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
// App.js
// Database
var db = require('./database/db-connector')
// Get an instance of mysql we can use in the app
var mysql = require('mysql')
// Create a 'connection pool' using the provided credentials
var pool = mysql.createPool({
connectionLimit : 10,
host : 'classmysql.engr.oregonstate.edu',
user : 'cs340_bolandan',
password : '5445',
database : 'cs340_bolandan'
})
// Export it for use in our applicaiton
module.exports.pool = pool;
const { engine } = require('express-handlebars');
var exphbs = require('express-handlebars'); // Import express-handlebars
app.engine('.hbs', engine({extname: ".hbs"})); // Create an instance of the handlebars engine to process templates
app.set('view engine', '.hbs'); // Tell express to use the handlebars engine whenever it encounters a *.hbs file.
/*
SETUP
*/
var express = require('express'); // We are using the express library for the web server
var app = express(); // We need to instantiate an express object to interact with the server in our code
PORT = 10314; // Set a port number at the top so it's easy to change in the future
/*
ROUTES
*/
app.get('/', function(req, res)
{
res.render('index'); // Note the call to render() and not send(). Using render() ensures the templating engine
}); // will process this file, before sending the finished HTML to the client.
/*
LISTENER
*/
app.listen(PORT, function(){ // This is the basic syntax for what is called the 'listener' which receives incoming requests on the specified PORT.
console.log('Express started on http://localhost:' + PORT + '; press Ctrl-C to terminate.')
});