-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (28 loc) · 1005 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
require("dotenv").config();
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const UserController = require('./controllers/user');
const CourseController = require('./controllers/course');
const app = express();
mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI);
const connection = mongoose.connection;
connection.on('connected', () => {
console.log('Mongoose Connected Successfully');
});
// If the connection throws an error
connection.on('error', (err) => {
console.log('Mongoose default connection error: ' + err);
});
app.use(bodyParser.json());
app.use(express.static(__dirname + '/client/build/'));
app.get('/', (req,res) => {
res.sendFile(__dirname + '/client/build/index.html')
})
app.use('/api/user', UserController);
app.use('/api/course', CourseController);
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log("Magic happening on port " + PORT);
})