-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (41 loc) · 1.21 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
require("dotenv").config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const port = process.env.PORT || 5000;
const database_uri = process.env.DB_URI;
mongoose.set('useFindAndModify', false);
// create express app
const app = express();
app.use(cors());
app.use(express.urlencoded({
extended: true
}));
// To parse the incoming requests with JSON payloads
app.use(express.json())
// Require routes
require('./app/routes/user.route.js')(app);
require('./app/routes/pokemon.route.js')(app);
require('./app/routes/gen.route.js')(app);
// Configuring the database
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(database_uri, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log("Successfully connected to the database");
}).catch(err => {
console.log('Could not connect to the database. Exiting now...\n', err);
process.exit();
});
// simple route
app.get('/', (req, res) => {
res.json({
"message": "Rowdyhacks 2022 Hackathon Project And Beyond - Retro Pokemon Game"
});
});
// listen for requests
app.listen(port, () => {
console.log("Server is listening on port: " + port);
});