-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (45 loc) · 1.09 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
42
43
44
45
46
47
48
49
50
51
52
53
54
const dotenv = require('dotenv');
const mongoose = require('mongoose');
dotenv.config({ path: './config.env' });
const app = require('./app');
//Adding port to access the app
const { PORT } = process.env;
//Database stuff
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
//connect method returns the promise
mongoose
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false
})
.then(() => {
console.log('DB connection successful');
});
//After schema, model - create the test tour
// const testTour = new Tour({
// name: 'The Sasan Gir',
// rating: 4.8,
// price: 688
// });
// const testTour2 = new Tour({
// name: 'Calgary Forester',
// rating: 3.9,
// price: 250
// });
//Saving to DB
// testTour
// .save()
// .then(doc => console.log(doc))
// .catch(err => console.error(err));
// testTour2
// .save()
// .then(doc => console.log(doc))
// .catch(err => console.log(err));
app.listen(PORT, () => {
// eslint-disable-next-line no-console
console.log(`Listening on ${PORT}`);
});