-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (48 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express=require("express")
const app=express()
const products=require("./products")
const mongoose=require("mongoose")
const cors=require("cors")
const bodyParser=require("body-parser")
const content=require("./schema")
const Content = require("./schema")
console.log(Content)
app.use(bodyParser.urlencoded({
extended:true
}))
app.use(bodyParser.json())
app.use(cors())
mongoose.connect("mongodb+srv://sunitha:[email protected]/firstdb?retryWrites=true&w=majority")
.then(()=>{
console.log("mongodb connected successfully")
})
.catch((err)=>{
console.log(err)
})
app.post("/add",(req,res)=>{
console.log("data from front end",req.body)
const {name,passcode}=req.body
const newData=new Content({
name,passcode
})
newData.save()
res.send("added")
})
app.get("/retrieve",(req,res)=>{
Content.find()
.then(found=>res.json(found))
})
app.get("/",(req,res)=>{
res.send("server started successfully")
})
app.post("/add",(req,res)=>{
})
app.get("/products",(req,res)=>{
res.json(products)
})
app.get("/name",(req,res)=>{
res.send("codegnan")
})
app.listen(4000,()=>
console.log("sever is started")
)