-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (34 loc) · 1023 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
43
44
45
46
const express = require("express"),
mongoose = require("mongoose"),
bodyParser = require("body-parser"),
passport = require('passport');
const app = express();
//BodyParser middleware
app.use(
bodyParser.urlencoded({
extended: false
})
);
app.use(bodyParser.json());
//Routes to diffrent functions
const users = require("./routes/api/users");
const profile = require("./routes/api/profile");
const posts = require("./routes/api/posts");
//MongDB config
const db = require("./config/key").mongoURI;
//MongoDB connection
mongoose
.connect(db, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log("MongoDB connected"))
.catch(err => console.log(err));
app.get("/", (req, res) => res.send("Hello world"));
app.use(passport.initialize());
require('./config/passport')(passport);
app.use("/users", users);
app.use("/profile", profile);
app.use("/posts", posts);
const port = process.env.PORT || 8080;
app.listen(port, () => console.log(`Listening on ${port}.`));