-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (35 loc) · 1.18 KB
/
app.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
// modules
const express = require("express");
const { json, urlencoded } = express;
const mongoose = require("mongoose");
const morgan = require("morgan");
const cors = require("cors");
require("dotenv").config();
const cookieParser = require("cookie-parser");
var bodyParser = require('body-parser');
const expressValidator = require("express-validator")
// app
const app = express();
// db
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(()=> console.log("DB connected")).catch((err) => console.log("DB error ", err));
//middleware
app.use(morgan("dev"));
app.use(express.json({limit: "3mb",extended:true}));
app.use(cors({origin: true, credentials: true}));
app.use(json());
app.use(urlencoded({extended: false}));
app.use(cookieParser());
app.use(expressValidator());
//routes
const commRoutes = require("./routes/community");
app.use("/communities", commRoutes);
const userRoutes = require("./routes/user");
app.use("/user", userRoutes);
// port
const port = process.env.PORT || 8080;
// listener
const server = app.listen(port, ()=> console.log("Server is running on ze port 8080."));