-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (40 loc) · 1.18 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
var express = require("express");
var bodyParser = require("body-parser");
var md5 = require('MD5');
var rest = require("./rest.js");
var app = express();
var mongoose = require("mongoose");
var url = 'mongodb://localhost/sws';
function REST(){
var self = this;
self.connectMonodb();
};
REST.prototype.connectMonodb = function() {
var self = this;
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
console.log("connected to mongodb server.");
self.configureExpress();
});
mongoose.connect(url);
}
REST.prototype.configureExpress = function() {
var self = this;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var router = express.Router();
app.use('/api', router);
var rest_router = new rest(router, md5);
self.startServer();
}
REST.prototype.startServer = function() {
app.listen(3000,function(){
console.log("All right ! I am alive at Port 3000.");
});
}
REST.prototype.stop = function(err) {
console.log("ISSUE WITH MONGODB \n" + err);
process.exit(1);
}
new REST();