-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
52 lines (39 loc) · 1.16 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
45
46
47
48
49
50
51
52
//ENTRY POINT FILE FOR THE APP
//DEFINING ALL MODULES
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cors =require('cors');
const passport = require('passport');
const mongoose = require('mongoose');
const config = require('./config/database');
const MongoClient = require('mongodb').MongoClient;
//CONNECTING TO DB
mongoose.connect(config.mongoURI);
//ON CONNECTION
mongoose.connection.on('connected', () =>{
console.log('CONNECTED TO MONGOOSE DB.');
});
//CONNECTION ERROR
mongoose.connection.on('error', (err) =>{
console.log('MONGOOSE DB CONNECTION ERROR : \n' + err);
});
const app = express();
const users = require('./routes/users');
//PORT NO.
const port = process.env.PORT || 3000;
//CORS MIDDLEWARE
app.use(cors());
//SET STATIC FOLDER
app.use(express.static(path.join(__dirname, 'public')));
//BODY PARSER MIDDLEWARE
app.use(bodyParser.json());
//PASSPORT MIDDLEWARE
app.use(passport.initialize());
app.use(passport.session());
require('./config/passport')(passport);
app.use('/users', users);
//STARTING SERVER
app.listen(port, () => {
console.log(`SERVER RUNNING ON PORT ${port}`);
});