-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
67 lines (59 loc) · 1.28 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
55
56
57
58
59
60
61
62
63
64
65
66
67
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config({ path: './config.env' });
const app = require('./app');
const DB = process.env.DATABASE.replace(
'<PASSWORD>',
process.env.DATABASE_PASSWORD
);
mongoose
// .connect(process.env.DATABASE_LOCAL, {
.connect(DB, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
})
// .then((con) => {
.then(() => {
// console.log(con.connections);
console.log('DB connection successful.');
});
// console.log(app.get('env'));
// console.log(process.env);
//schema
const tourSchema = new mongoose.Schema({
name: {
type: String,
required: [true, 'a tour must have a name'],
unique: true,
},
rating: {
type: Number,
default: 4.5,
},
price: {
type: Number,
required: [true, 'a tour must have a price'],
},
});
//model
const Tour = mongoose.model('Tour', tourSchema);
const testTour = new Tour({
name: 'The Forest Hiker',
rating: 4.7,
price: 232,
});
testTour
.save()
.then((doc) => {
console.log(doc);
})
.catch((err) => {
console.log('ERROR:🔥 ', err);
});
//start server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`app running on port ${port}...`);
});