-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (42 loc) · 1.22 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
53
54
55
56
57
//
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const passport = require('passport');
const config = require('./config/database');
//connecting to db
mongoose.connect(config.database);
//on connection
mongoose.connection.on('connected', () =>{
console.log('connected to database:'+config.database);
});
//on error
mongoose.connection.on('error', (err) =>{
console.log('error:'+err);
});
//initialising app variable with express
const app = express();
const users = require('./routes/users');
//initialize port variable
const port = 3000;
//set up client side files(static files)
app.use(express.static(path.join(__dirname, 'client')));
//index route
app.get('/',(req, res)=>{
res.send('invalid endpoint')
});
//start server
app.listen(port, () =>{
console.log('started server on port'+port);
});
//to allow access from different domains
app.use(cors());
//body parser passes incoming requests eg from submitted forms
app.use(bodyParser.json());
//passport
app.use(passport.initialize());
app.use(passport.session());
require('./config/passport')(passport);
app.use('/users', users);