-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (40 loc) · 1.08 KB
/
app.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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const Listing = require("./models/listing.js");
// const path = require("path");
// const methodOverride = require("method-override");
const MONGO_URL = "mongodb://127.0.0.1:27017/wanderLust";
main()
.then(() => {
console.log("connected to DB");
})
.catch((err) => {
console.log(err);
});
async function main() {
await mongoose.connect(MONGO_URL);
};
app.get("/", (req, res) =>{
res.send("Hi, I am groot");
});
app.get("/listings", (req, res) =>{
Listing.find({}).then((res) =>{
console.log(res);
})
})
// app.get("/testListing", async (req, res) =>{
// let sampleListing = new Listing({
// title: "My New Villa",
// description: "By the beach",
// price: 12000,
// location: "Motihari, Bihar",
// country: "India"
// });
// await sampleListing.save();
// console.log("sample was saved");
// res.send("successful testing");
// });
app.listen(8080, () =>{
console.log("server is listening to port 8080");
});