Archived
mongodb implementation
This commit is contained in:
1 parent
3e62017db9
commit
90094b9594
5 files changed
+139
-44
No files matched your search
+19
-3
@@ -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, () => {
|
||||
|
||||
Reference in new issue
Block a user