-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (32 loc) · 1.26 KB
/
server.js
File metadata and controls
50 lines (32 loc) · 1.26 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
require('dotenv').config();
const express = require('express')
const mongoose = require('mongoose')
const app = express();
const bodyparser = require('body-parser')
const cors = require('cors');
app.use(cors());
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended: true}))
const PORT_NUMBER = process.env.PORT || 8085;
const MONGO_URL = process.env.MONGO_URL || 'mongodb://localhost/videogame';
//#region ********** DATABASE RESOURCES **********/
mongoose.set("strictQuery", false);
mongoose.connect(MONGO_URL, {
useNewUrlParser: true
});
const db = mongoose.connection;
//This is in the case of an error with the connection
db.on('error', err => console.log(err));
//This is to run once we have connected to the database
db.once('open', () => console.log('Connected To The Database'));
//#endregion
//#region ********** ROUTES **********/
//Route for the index file
const indexRouter = require('./routes/index');
const userValidationRouter = require('./routes/uservalidation');
const gameRouter = require('./routes/gameIndex');
//#endregion
app.use('/api/v1/user', indexRouter);
app.use('/api/v1/user/validation', userValidationRouter);
app.use('/api/v1/games', gameRouter);
app.listen(PORT_NUMBER, () => { console.log(`Connected To ${PORT_NUMBER}`);})