-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.13 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const path = require('path');
const passport = require('passport');
const cors = require('cors');
// Initialize app
const app = express();
// Middlewares
app.use(bodyParser.urlencoded({
extended: false,
}));
app.use(bodyParser.json());
app.use(cors());
app.use(passport.initialize());
require('./config/passport')(passport);
// Setting Static Directory
app.use(express.static(path.join(__dirname, 'public')));
// Import DB config
const db = require('./config/keys');
mongoose.connect(db.mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log(`Database sucessfully connected ${db.mongoURI}`);
}).catch((err) => {
console.log(`Unable to connect to Database ERROR : ${err}`);
});
// Require all the Routes
const users = require('./routes/api/users');
app.use('/api/users', users);
app.get('*', (res, req) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
});
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server is listening on ${port}`);
});