forked from phlip9/txtcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (27 loc) · 894 Bytes
/
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
'use strict';
// required packages
var express = require("express");
var bodyParser = require("body-parser");
var setupRoutes = require('./route.js');
var cors = require('cors');
var mongoose = require('mongoose');
// set up app with middlewares
var app = express();
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// connect to database
var path = process.env.MONGOHQ_URL + "/txtcoin";
mongoose.connect(path);
mongoose.connection.on("error", function() {
console.error.bind("[MongoDB] Connection Failed: ");
});
mongoose.connection.once("open", function() {
console.log("[MongoDB] Connection Success!!! PATH: %s", path);
});
setupRoutes(app);
//Server Listening to Port
var server = app.listen((process.env.PORT || 5000), function(){
console.log("[Server] Listening at %s", server.address().port);
});
module.exports = app;