-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
70 lines (55 loc) · 1.86 KB
/
server.js
File metadata and controls
70 lines (55 loc) · 1.86 KB
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
//EXPRESS SETUP
var express = require("express");
var app = express();
// Serve static content for the app from the "public" directory in the application directory.
app.use(express.static("public"));
//BODY-PARSER STANDARD SETUP WITH EXPRESS
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// Set the port of our application
// process.env.PORT lets the port be set by Heroku
var PORT = process.env.PORT || 8080;
var exphbs = require("express-handlebars");
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
//REQUIRE other file exports
var connection = require("./config/connection");
// Import routes and give the server access to them.
var routes = require("./controllers/cats_controller.js");
app.use(routes);
//ESTABLISH CONNECTION TO DATABASE USING CONNECTION CONFIG FILE
connection.connect(function(err) {
if(err)
{
console.log("error connecting to mySQL database");
return;
}
console.log("Connected to database at " + connection.threadId);
});
//TEST SECTION ONLY
// //IMPORTS
// var orm = require("./config/orm");
// var cat = require("./models/cats_model");
// Console log all the cat info
// orm.selectAll("cats");
// cat.all(function(res) {
// console.log(res);
// });
//add a new cat
// orm.insertOne("Italic");
// cat.insert("William", function(res){
// console.log(res);
// });
//update an entry
// orm.updateOne("cat_name", "Fluffy Kitty", 1);
// cat.update("pet_or_not", 1, 2, function(res){
// console.log(res);
// });
//NOTE- true/false boolean field requires an integer input of 0 or 1
//END TEST SECTION ONLY
// START LISTENER - begin listening to client requests
app.listen(PORT, function() {
// Log (server-side) when our server has started
console.log("Server listening on: http://localhost:" + PORT);
});