mongodb implementation

This commit is contained in:
Maciej Kotowski committed 2021-10-01 21:19:02 +02:00
1 parent 3e62017db9
commit 90094b9594
5 files changed
+139 -44

No files matched your search

+19 -3
View File
@@ -2,9 +2,25 @@
const express = require('express')
const app = express()
const port = process.env.PORT || 3000
app.get('/', (req, res) => {
res.send('Hello World!')
const { MONGO_URI } = require("./config");
const mongoose = require("mongoose");
const events = require("./models/events");
mongoose
.connect(MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("connected"))
.catch((err) => console.log(err));
app.get('/', async (req, res) => {
try {
const event = await events.find({ mess : "one" });
if (!event) throw Error("something went wrong");
console.log(event)
res.status(200).json(event);
} catch (err) {
res.status(400).json({ msg: err });
}
})
app.listen(port, () => {