-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (29 loc) · 838 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express=require('express');
const app=express();
var admin = require("firebase-admin");
var serviceAccount = require("./key.json");
app.use(express.json());
app.use(express.urlencoded({extended:true}));
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db=admin.firestore();
app.post('/create',async(req,res)=>{
try{
const id=req.body.email;
const userJson={
email:req.body.email,
firstname:req.body.firstName,
lastname:req.body.lastName
};
const response=db.collection("user").doc(id).set(userJson);
res.send(response);
} catch(error)
{
res.send(error);
}
})
const PORT = process.env.PORT || 8080;
app.listen(PORT,()=>{
console.log(`Server running on port ${PORT}`);
})