forked from chanakaDe/Mint-REST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (33 loc) · 837 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
38
39
var express = require("express");
var bodyParser = require("body-parser");
var morgan = require("morgan");
var config = require("./config");
var mongoose = require("mongoose");
var cors = require('cors');
var app = express();
/**
* Using CORS to reduce CROSS Origine.
*/
app.use(cors());
/**
* Connecting to MongoDB using Mongoose.
*/
mongoose.connect(config.database, function (err) {
if (err) {
console.error(err);
} else {
console.log("Connected to database");
}
});
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.use(morgan('dev'));
var api = require('./app/routes/api')(app, express);
app.use('/api', api);
app.listen(config.port, function (err) {
if (err) {
console.log(err);
} else {
console.log("Listening on port 3000");
}
});