-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (31 loc) · 898 Bytes
/
app.js
File metadata and controls
41 lines (31 loc) · 898 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
40
41
//Imports
const express = require('express');
const app = express();
const mongoose = require('mongoose');
// cors for cross domain data requests.
const cors = require('cors');
//Import routes
var landmarksRoute = require('./routes/landmarks');
//Import env
require('dotenv/config');
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Middlewares
app.use(cors());
app.use('/landmarks', landmarksRoute);
//ROUTES
app.get('/', (req, res) => {
res.send('Send get/post/delete/patch requests for/with data to https://walkerapi.herokuapp.com/landmarks' );
});
//connect to database
mongoose.connect(process.env.DB_CONNECTION,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => { console.log("Connected to db");
})
//listen to server
let port = process.env.PORT;
if (port == null || port == "") {
port = 7000;
}
console.log(port);
app.listen(port);