-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
executable file
·63 lines (52 loc) · 1.7 KB
/
server.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
// NOTES
// ==========================================
// Express is a web framework for Node.js that makes backend configuration easier.
// website: http://expressjs.com
//
// package.json
// guide: http://browsenpm.org/package.json
//
// require() is like #include in C/C++ and import in Java.
// it allows you to load JS files.
// SETUP
// ==========================================
// creates an Express application
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
var bodyParser = require('body-parser');
// USE
// ==========================================
// app.use([path,] function [, function...])
// Mounts the middleware function(s) at the path. If path is not specified, it defaults to “/”
//
// set the root directory to public
app.use(express.static(__dirname+'/public'));
// bodyParser() lets us get the data from a POST
// we are parsing the data in json format below
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
// CONFIG
// ==========================================
var dbConfig = require('./config/db');
var mongoose = require('mongoose');
//Connect to DB
mongoose.connect(dbConfig.url);
// SET
// ==========================================
// app.set(name, value)
// Assigns setting name to value, where name is one of the properties from the app settings table
// ex.
// app.set('title', 'My Site');
// app.get('title'); // "My Site"
//
// here we're setting our view engine to ejs
app.set('view engine', 'ejs');
// set views folder directory
app.set('views', __dirname+ '/views');
// ROUTES
// ==========================================
require('./route')(app);
// LAUNCH
// ==========================================
app.listen(port);