-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
50 lines (41 loc) · 1.28 KB
/
server.js
File metadata and controls
50 lines (41 loc) · 1.28 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
const express = require('express')
const bodyParser = require('body-parser')
const dbConfig = require('./config/db.config')
const cors = require('cors')
const mongoose = require("mongoose");
const app = express()
require('dotenv').config()
app.use(cors())
// parse requests of content-type - application/json
app.use(bodyParser.json())
// parse request of content type = application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended: true}))
// SETUP MONGOOSE
const db = require('./models/')
// set the database URI
dbURI = process.env.MONGODB_URI || `mongodb://${dbConfig.HOST}:${dbConfig.PORT}/${dbConfig.DB}`
// connect to mongo database
db.mongoose.connect(dbURI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Successfully connected to MongoDB.");
})
.catch(err => {
console.error("Connection error", err);
process.exit();
});
// simple route, do I work?
app.get('/', (req,res) => {
res.json({message: "Welcome to the home page"})
})
// import the routes we wrote
require('./routes/auth.routes')(app)
require('./routes/user.routes')(app)
require('./routes/dog.routes')(app)
// set the port, listen for request
const PORT = process.env.PORT || 8080
app.listen(PORT, ()=> {
console.log(`Server running on ${PORT}`)
})