Skip to content

Commit

Permalink
inserting record to data base
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Jul 15, 2022
1 parent 410a4e0 commit 018338d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 25 additions & 0 deletions postApi.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 018338d

Please sign in to comment.