-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
47 lines (36 loc) · 1.24 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
// Dependencies
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
// Initialize Express
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
// Sets the port for the server to listen on
const PORT = process.env.PORT || 3000;
// Use body-parser for handling form submissions
app.use(bodyParser.urlencoded({ extended: true }));
// Sets up the Express app to handle data parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Sets the server to use the public directory for static assets
app.use(express.static(path.join(__dirname, 'public')));
// Routes
require('./routes/api-routes.js')(app);
require('./routes/html-routes.js')(app);
// Socket.io Routes
require('./sockets/todo-sockets')(io);
//Set up promises with mongoose
mongoose.Promise = global.Promise;
//Connect to the Mongo DB
mongoose.connect(
process.env.MONGODB_URI || "mongodb://todo:[email protected]:31199/heroku_5jg118hc",
{
useMongoClient: true
}
);
// Starts our server on the predefined PORT
server.listen(PORT, function(){
console.log(`App is now listening on PORT ${PORT}`)
})