-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (39 loc) · 1.33 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
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const dotenv = require("dotenv");
const morgan = require("morgan");
// const methodOverride = require("method-override");
const passport = require("passport");
// const session = require("express-session");
// const db = require("./config/keys").mongoURI;
const connectDB = require("./config/db");
var user = require("./routes/api/users");
var main = require("./routes/api/main");
var dept = require("./routes/department/dept");
var admin = require("./routes/department/admin");
dotenv.config({ path: "./config/config.env" });
// Passport config
require("./config/passport")(passport);
connectDB();
const app = express();
//parse url encoded bodies as sent by forms
app.use(bodyParser.urlencoded({ extended: false }));
//parse json bodies(as sent by api clients)
app.use(bodyParser.json());
// Passport middleware
app.use(passport.initialize());
if (process.env.NODE_ENV === "development") {
app.use(morgan("dev"));
}
//setting up routes
app.use("/main", main);
app.use("/api/users", user);
app.use("/department/dept", dept);
app.use("/department/admin", admin);
const PORT = process.env.PORT || 5000;
app.listen(
PORT,
console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`)
);