-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (33 loc) · 882 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
40
41
42
"use strict";
const express = require("express");
const morgan = require("morgan");
const bodyParser = require('body-parser');
const mongoose = require("mongoose");
const config = require("./config");
const api = require("./api/v1");
// Connect to database
mongoose.connect(config.db.url);
const app = express();
app.use(morgan("common"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use("/api", api);
app.use("/api/v1", api);
app.use( (req, res, next) => {
console.log("Route not found");
res.status(404);
res.json({
"error": "Error. Route not found"
});
});
app.use( (err, req, res, next) => {
console.log("Error");
res.status(500);
res.json({
"error": `${err}`
});
});
var server = app.listen( 8080, function () {
var port = server.address().port;
console.log("App now running on port", port);
});