-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (28 loc) · 785 Bytes
/
server.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
require("./dbconnection");
const express = require("express");
const bodyparser = require("body-parser");
const mongoose = require("mongoose");
const {User} = require("./user");
var app = express();
app.use(bodyparser.json());
app.post("/insertuser",(req,res)=>{
var newUser = new User({
name : req.body.name,
company : req.body.company
});
newUser.save().then((data)=>{
res.send({_id : data._id}).status(200);
}).catch((err)=>{
res.send(err).status(400);
})
})
app.get("/getuser",(req,res)=>{
User.findById(req.query.id).then((data)=>{
res.send(data).status(200);
}).catch((err)=>{
res.send(err).status(400);
})
})
app.listen(3000,()=>{
console.log("Application started at port 3000");
})