-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (31 loc) · 899 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (31 loc) · 899 Bytes
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
const express = require('express'),
path = require('path'),
bodyParser = require('body-parser'),
cors = require('cors'),
mongoose = require('mongoose'),
config = require('./config/database');
//CONNECT TO DATABASE
mongoose.connect(config.database, { useNewUrlParser: true });
mongoose.connection.on('connected', () => {
console.log('Connected to database ' + config.database);
});
mongoose.connection.on('error', error => {
console.log('Database error ' + error);
});
const app = express();
const leaderboard = require('./routes/leaderboard');
const port = 3000;
//MIDDLWARE
app.use(cors());
app.use(bodyParser.json());
//STATIC FILE
app.use(express.static(path.join(__dirname, 'public')));
//ROUTES
app.use('/leaderboard', leaderboard);
app.get('/', (req, res) => {
res.send('Invalid endpoint');
});
//STARTING SERVER
app.listen(port, () => {
console.log('Server Running...');
});