Skip to content

Commit

Permalink
Included MongoDb to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
pribylmartinnet committed Mar 23, 2022
1 parent b462a20 commit 7e8e853
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 10 deletions.
12 changes: 5 additions & 7 deletions controllers/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const db = require("../db")
const router = express.Router()


router.get("/sum", function (req, res){
router.get("/sum", function (req, res) {

try {
res.status(200).send(math.sum(Number(req.query.a), Number(req.query.b)))
Expand All @@ -14,17 +14,15 @@ router.get("/sum", function (req, res){

})



router.get("/", function (req, res){
router.get("/", function (req, res) {
db.run()
res.status(200).send("Ahoj")
})

router.post("/", function (req, res){
router.post("/", function (req, res) {
try {
let topic = req.body.topic
let desc = req.body.dexsription
let desc = req.body.dessription
console.log(topic)
res.status(201).send("A topic was created")
} catch (err){
Expand All @@ -33,7 +31,7 @@ router.post("/", function (req, res){

})

router.get("/:id", function (req, res){
router.get("/:id", function (req, res) {
try {
let id = req.params.id
console.log(id)
Expand Down
6 changes: 4 additions & 2 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require('dotenv').config()
const { MongoClient } = require("mongodb");
const { MongoClient } = require("mongodb")
const client = new MongoClient(process.env.DB_CONN);

async function run() {
try {

try {
// Connect the client to the server
await client.connect();
// Establish and verify connection
Expand All @@ -13,6 +14,7 @@ async function run() {
// Ensures that the client will close when you finish/error
await client.close();
}

}


Expand Down
142 changes: 142 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"dotenv": "^16.0.0",
"express": "^4.17.3"
"express": "^4.17.3",
"mongodb": "^4.4.1"
}
}

0 comments on commit 7e8e853

Please sign in to comment.