forked from mkdinh/Fission
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
51 lines (38 loc) · 1.17 KB
/
server.js
File metadata and controls
51 lines (38 loc) · 1.17 KB
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
// IMPORT DEPENDENCIES
// --------------------------------------------
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
const passport = require("passport");
// SETTING UP DATABASE
// --------------------------------------------
// leverage ES6 promise feature
mongoose.Promise = global.Promise;
const LOCAL_URI = "mongodb://localhost/chain-reaction"
// connect to mongoDB
mongoose.connect(
process.env.MONGODB_URI || LOCAL_URI,
{
useMongoClient: true
}
);
// SETTING UP SERVER
// --------------------------------------------
// create instance of express
let app = express();
// assign port to listen to
let PORT = process.env.PORT || 3001;
// use passport midware
app.use(passport.initialize());
app.use(passport.session())
// parse body in HTTP request
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// server static files
app.use(express.static("./client/build"));
// use routes
app.use(routes);
// START SERVER
// --------------------------------------------
app.listen(PORT, () => console.log(`listen to port: ${PORT}`));