-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (27 loc) · 918 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
// packages imports
const express = require('express');
const bodyParser = require('body-parser');
const passport = require('passport');
const mongoose = require('mongoose');
// variables imports
const users = require('./routes/api/users');
const dbURL = require('./config/keys').dbURL;
// choose db depending on NODE_ENV
mongoose
.connect(dbURL)
.then(res => console.log('db connected successfully!'))
.catch(err => console.log('db connection error: ', err));
// initialize express app
const app = express();
// body parser middleware
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// passport middleware
app.use(passport.initialize());
// passport config
require('./config/passport')(passport);
// creating routes
app.use('/', users);
const port = process.env.PORT || 3030;
// creating node server
app.listen(port, () => console.log(`Server running on port: ${port}`));