-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 840 Bytes
/
index.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
//Main starting point of the application
const express = require("express");
const http = require("http");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const app = express();
const router = require("./router");
const mongoose = require("mongoose");
const cors = require("cors");
// DB setup
// creates a new database in mongo called auth
mongoose.connect("mongodb://localhost:27017/auth", {useMongoClient: true});
// middlewares:
// log incoming requests
app.use(morgan("combined"));
// allow cors
app.use(cors());
// extract the request body, turn it into a json and exposes it on req.body
app.use(bodyParser.json({type: "*/*"}));
router(app);
// server setup
const port = process.env.PORT || 3090
const server = http.createServer(app);
server.listen(port);
console.log("Server listening on:", port);