-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathapp.js
44 lines (34 loc) · 1.29 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
const http = require('http');
const express = require('express');
const consolidate = require('consolidate');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes'); //File that contains our endpoints
const socketEvents = require('./socket-events');
const app = express();
app.use(bodyParser.urlencoded({
extended: true,
}));
app.use(bodyParser.json({
limit: '5mb'
}));
app.set('views', 'views'); // Set the folder-name from where you serve the html page.
app.use(express.static('./public')); // setting the folder name (public) where all the static files like css, js, images etc are made available
app.set('view engine', 'html');
app.engine('html', consolidate.handlebars); // Use handlebars to parse templates when we do res.render
// connect to Database
const db = 'mongodb://localhost:27017/uberForX';
mongoose.connect(db).then(value => {
// Successful connection
console.log(value.models);
}).catch(error => {
// Error in connection
console.log(error);
});
app.use('/', routes);
const server = http.Server(app);
const portNumber = 8000; // for locahost:8000
server.listen(portNumber, () => { // Runs the server on port 8000
console.log(`Server listening at port ${portNumber}`);
socketEvents.initialize(server);
});