diff --git a/api.js b/api.js new file mode 100644 index 0000000..a0c13ef --- /dev/null +++ b/api.js @@ -0,0 +1,12 @@ +const express = require('express'); +const dbConnect = require('./dbConnFile'); +const app = express(); + +app.get('/' , async (req , res) => { + let data =await dbConnect(); + data = await data.find().toArray(); + console.log(data); + res.send(data); + +}); +app.listen(8000); \ No newline at end of file diff --git a/postApi.js b/postApi.js new file mode 100644 index 0000000..5aaf589 --- /dev/null +++ b/postApi.js @@ -0,0 +1,25 @@ +const express = require('express'); +const dbConnect = require('./dbConnFile'); +const app = express(); + +//telling the node that we are using json data formate +app.use(express.json()); + +//get api +app.get('/' , async (req , res) => { + let data =await dbConnect(); + data = await data.find().toArray(); + console.log(data); + res.send(data); + +}); + + +//post api +app.post('/' , async (req , res) => { + let data = await dbConnect(); + data = await data.insert(req.body); + res.send(data); +}); + +app.listen(8000); \ No newline at end of file