-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
39 lines (25 loc) · 1.14 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
"use strict";
// Modules =================================================
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var morgan = require('morgan');
// Required files ==========================================
var configDB = require('./config/database.js');
// Configuration ===========================================
var port = process.env.PORT || 8080; // set our port
mongoose.connect(configDB.url); // connect to our database
var connection = mongoose.connection;
connection.once('open', function(){
console.log('Successfully connected to: ' + configDB.url)
});
// Express application middleware
app.use(morgan('dev')); // log every request to the console
app.use(bodyParser.json()); // get information from html forms
app.use(express.static(__dirname + '/public')); // set the static files location
// Routes ==================================================
// Start app ===============================================
app.listen(port, function(){
console.log('Magic happens on port ' + port);
});